Re: Rewriting a shell script

From: Laurent Bercot <ska-skaware_at_skarnet.org>
Date: Mon, 30 Nov 2015 19:06:02 +0100

On 30/11/2015 17:57, Colin Booth wrote:
> Eh what? define -sn splits ${A} into N words, of which the first is
> put into ${B} and the rest dropped.i

  Nope. It will split ${A} into N words, drop the last word if ${A}
isn't terminated with a delimiter, and put all those words into B.


> Actually, on further testing, it looks like what's happening is that
> -n throws away the last item in non-newline terminated values.

  Yes. More precisely, non-delimiter-terminated.


> Not sure if that's intentional, but it's definitely not what the
> documents say is supposed to happen.

  Working as intended *and* documented:
http://skarnet.org/software/execline/el_transform.html#split
Section "How it works":

   The last sequence of characters in the value will be recognized as a
   word even if it is not terminated by a delimiter, unless you have
    requested chomping and there was no delimiter at the end of the value
    before the chomp operation - in which case that last sequence will not
    appear at all.

  Yeah, splitting + chomping is a bit of a tricky one, but the behaviour
allows you to handle all the cases you may need. :)

-- 
  Laurent
Received on Mon Nov 30 2015 - 18:06:02 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC