Greg Wooledge wrote in <zsfsx6adq8w8t...@wooledge.org>: |On Fri, Aug 23, 2024 at 01:28:49 +0200, Steffen Nurpmeso wrote: |> a() { echo $#,1=$1,2=$2,"$*",$*,; } |> set -- a b c |> echo 2 |> IFS=:; echo "$*"$*; a $* "$*";
I want to point out that bash in particular has the very dubious description in its manual page If IFS has a value other than the default, then sequences of the whitespace characters space, tab, and newline 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 charac‐ ter). So IFS whitespace only if part of $IFS. Any character in IFS that is not IFS whitespace, along with any adjacent IFS whitespace characters, delimits a field. So this "adjacent" even if *not* part of $IFS. A sequence of IFS whitespace characters is also treated as a delimiter. So this means that *regardless* of whatever $IFS is, the three IFS whitespace characters are $IFS anyway *if* that is set to a nin-empty non-default value. I do this for things i have documented but forgotten. Good. If the value of IFS is null, no word splitting occurs. The standard says in 2.6.5 that 3. A byte sequence in the input which resulted from an expansion and which forms an IFS white space character: Remove that byte sequence from the input, consider the new leading input byte sequence, and repeat this step. 4. A byte sequence in the input which resulted from an expansion and which forms an IFS character that is not IFS white space: Remove that byte sequence from the input, but note it was observed. At this point [after $IFS and $IFS whitespace etc], if the candidate is not empty, or if a sequence of bytes representing an IFS character that is not IFS white space was seen at step 4, then a field is said to have delimited, and the candidate shall become an output field. So after some fresh thinking it seems this practically means what bash documents. I have to say i still have a lot of problems wrapping my head against the term At this point [after $IFS and $IFS whitespace etc], if the candidate is not empty, or if a sequence of bytes representing an IFS character that is not IFS white space was seen at step 4, then a field is said to have delimited, It seems to me, now, that the actual point here is that IFS whitespace can give no empty output in say a IFS=: case, whereas the colon in $IFS *can* create empty output tokens. Thank you. --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)