Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    I actually agree with @StéphaneChazelas that it (mostly) confuses things more than helping...but I found it helpful, personally, so I upvoted. I now have a better idea (and some examples) of how IFS actually works. What I don't get is why it would ever be a good idea to set IFS to something other than default. Commented Jan 9, 2016 at 4:12
  • 1
    @Wildcard - it's a field delimiter. if you have a value in a variable that you want to expand to multiple fields you split it on $IFS. cd /usr/bin; set -f; IFS=/; for path_component in $PWD; do echo $path_component; done prints \n then usr\n then bin\n. The first echo is empty because / is a null field. The path_components can have newlines or spaces or whatever - wouldn't matter because the components were split on / and not the default value. people do it w/ awk all the time, anyway. your shell does it too Commented Jan 9, 2016 at 6:40
  • "$@" is of course special, and doesn't really obey any other rule. I don't consider $* to be special because unquoted, it will undergo word splitting as you would expect, whereas quoted it becomes one blob, as you would expect. For that reason $* and "$*" are almost entirely useless, the former because you would hardly want new word splitting on the parameters, and the latter because you would hardly want them as one blob. Commented Aug 3, 2020 at 3:01
  • 1
    @xpusostomos, $* is special because when unquoted it can produce multiple words even if IFS is set to the empty string (which generally would disable word splitting). Quoted "$*" can be useful e.g. to join the positional parameters into one string for printing. Commented Aug 1, 2021 at 20:49
  • @ikkachu wow, I didn't know that. Too many weird rules in /bin/sh Commented Aug 3, 2021 at 3:37