Using the shell's 'set' command to parse a variable


I couldn't find any reference to this in any of my books on shell programming, but in a script a friend of mine was debugging-he didn't write it, it came from a vendor--we saw the following demonstrated:

$ x="Hello my name is"

$ set $x

$ echo $1
hello

$ echo $2
my

In other words, using the set command on the string contained in a variable splits the string, using whitespace as the delimiter, into the variables $1, $2, and so on, which could be very handy in scripting. There doesn't appear to be any way to set the delimiter to a different character. Additionally, if the string contains more than nine values or words, you must reference those using ${10}, ${11}, and so on.

10/14/2003