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.

9
  • Nice - I knew about $IFS but hadn't seen how it could be used.
    – Rob I
    Commented May 9, 2012 at 19:20
  • I used triplee's example and it worked exactly as advertised! Just change last two lines to <pre> myvar1=echo $1 && myvar2=echo $2 </pre> if you need to store them throughout a script with several "thrown" variables.
    – Sigg3.net
    Commented Jun 19, 2013 at 8:08
  • 1
    No, don't use a useless echo in backticks.
    – tripleee
    Commented Jun 19, 2013 at 13:25
  • 4
    This is a really sweet solution if we need to write something that is not Bash specific. To handle IFS troubles, one can add OLDIFS=$IFS at the beginning before overwriting it, and then add IFS=$OLDIFS just after the set line. Commented Mar 27, 2015 at 6:46
  • 3
    Maybe add a set -f to disable pathname expansion before set -- $STR, or it will capture paths files names if $STR contains patterns.
    – Léa Gris
    Commented Oct 11, 2019 at 16:56