[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

why must non-standard $IFS members be treated so differently ?

From: Jason Vas Dias
Subject: why must non-standard $IFS members be treated so differently ?
Date: Sun, 29 Jul 2012 15:23:29 +0100

Good day Chet, list -
 I'm concerned about the difference in output of these functions with
the example input
 given on the '$' prefixed line below (with 4.2.29(2)-release

     function count_args     {                v=($@);  echo address@hidden; }

     function count_colons {  IFS=':' ;    v=($@);  echo address@hidden; }

 $ echo $(count_args 1 2 3\ 4) $(count_colons 1:2:3\:4)
 3 4

 It appears to be impossible for an item delimited by 'X' to contain
an escaped  'X' ('\X')  if 'X' is not
 a standard delimiter (' ', '<TAB>') .  Quoting doesn't seem to help either:

 $ echo $(count_args 1 2 3\ 4) $(count_colons 1:2:3':4')
 3 4

To me, this appears to be a bug.

But I bet you're going to tell me it is a feature ?
Please explain.

Thanks & Regards,

BTW, documentation on $IFS does not appear to mention this issue:

   Word Splitting
       The shell scans the results of parameter expansion, command
substitution, and arithmetic expansion that did not occur  within
       double quotes for word splitting.

       The  shell  treats  each  character of IFS as a delimiter, and
splits the results of the other expansions into words on these
       characters.  If IFS is unset, or its value is exactly
<space><tab><newline>, the default, then sequences of  <space>,
       and <newline> at the beginning and end of the results of the
previous expansions are ignored, and any sequence of IFS charac-
       ters not at the beginning or end serves to delimit words.  If
IFS has a value other than the default, then sequences  of  the
       whitespace  characters space and tab are ignored at the
beginning and end of the word, as long as the whitespace character is
       in the value of IFS (an IFS whitespace character).  Any
character in IFS that is not IFS whitespace, along with any  adjacent
       IFS whitespace characters, delimits a field.  A sequence of IFS
whitespace characters is also treated as a delimiter.  If the
       value of IFS is null, no word splitting occurs.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]