Problem with sh/ksh quoting
Brad Appleton
brad at SSD.CSD.HARRIS.COM
Sat Nov 3 06:32:48 AEST 1990
In article <4101 at awdprime.UUCP> tif at doorstop.austin.ibm.com (Paul Chamberlain) writes:
>In article <16289 at s.ms.uky.edu> kherron at ms.uky.edu (Kenneth Herron) writes:
>> line="this is 'a test'"
>> ...
>>I *want* it to produce:
>>this
>>is
>>a test
>
>Nice challenge. I finally got it, and you don't have to change things
>as dramatically as other people had posted. My method works like this:
>
> line='this is "a test"'
> eval set -- $line
> for word
> do
> echo $word
> done
>
This is fine and dandy except that you have now LOST your positional parameters
(and if you are in a script - you may still need them). Furthermore - saving
your parameters first by doing something like:
save_args="$*"
Is no help because now you will need to exercise some even fancier footwork to
get the parameters back the way they were if any contained IFS characters.
Like I said before - if you have the Korn shell, this is all *very* simple
if you create an array using "set -A" (or "set +A") and iterate your for-loop
based on "$array[@}" (the quotes are needed here). If you are using the
Bourne shell AND no longer need your postional parameters, then the method
described above will suit you just fine - If you still need the positional
positonal parameters (with sh) though - you'd better find another way (two
have been posted already).
______________________ "And miles to go before I sleep." ______________________
Brad Appleton brad at ssd.csd.harris.com Harris Computer Systems
uunet!hcx1!brad Fort Lauderdale, FL USA
~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~
More information about the Comp.unix.shell
mailing list