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*

8
  • 1
    You make it sound like "$@" is the same as "$*" in a scalar assignment. It is not. The bash shell would not use the first character of $IFS as delimiter with "$@", but space (always). Commented Mar 19, 2021 at 9:43
  • 1
    Another way to temporarily "save and restore" IFS: IFS=_$IFS (do stuff) IFS=${IFS#?}. (This sets the first character of IFS to an _, and then removes it). Commented Mar 19, 2021 at 9:48
  • @Kusalananda Hah, I didn't know that about args="$@". From a quick test, bash and ksh use "` ", but zsh and dash use the first char of IFS`. Fortunately, this isn't really something you should do, so not an incompatibility I'm going to worry about. Commented Mar 19, 2021 at 10:05
  • Yeah, using "$@" in a scalar context doesn't really make much sense. That's where you use "$*" after all. Commented Mar 19, 2021 at 10:07
  • 1
    Luckily (/s), you can always do something like unset savedIFS; [ "${IFS+set}" ] && savedIFS=$IFS;, then do your thing, and then unset IFS; [ "${savedIFS+set}" ] && IFS=$savedIFS; ... Commented Mar 19, 2021 at 10:19