bug-bash
[Top][All Lists]
Advanced

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

IFS whitespace definition


From: Greg Wooledge
Subject: IFS whitespace definition
Date: Thu, 17 Oct 2024 18:44:59 -0400

This issue came up on the Libera #bash IRC channel today:

Between bash 4.4 and 5.0, the definition of "IFS whitespace" has apparently
been expanded:

hobbit:~$ bash-4.4
hobbit:~$ ( s=$'a\r\r\rb'; IFS=$'\r' read -ra a <<< "$s"; declare -p a )
declare -a a=([0]="a" [1]="" [2]="" [3]="b")
hobbit:~$ exit
hobbit:~$ bash-5.0
hobbit:~$ ( s=$'a\r\r\rb'; IFS=$'\r' read -ra a <<< "$s"; declare -p a )
declare -a a=([0]="a" [1]="b")
hobbit:~$ exit

In bash 4.4 and earlier, IFS whitespace is always space + tab + newline.
But in 5.0 and later, it's "whatever the locale's isspace() allows",
along with some kind of 0x00 to 0x7f range check (thanks emanuele6).

Now, that's not necessarily bad, but the man page still says:

    ... 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  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. ...

"IFS whitespace" is not formally defined here, but it *looks* like
the text is saying that IFS whitespace is only space, tab, and newline
(which used to be true).

The man page should clarify this.



reply via email to

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