Article View: comp.unix.shell
Article #1702Re: Problem with sh/ksh quoting
From: Brad Appleton
Date: Fri, 02 Nov 1990 19:32
Date: Fri, 02 Nov 1990 19:32
40 lines
2198 bytes
2198 bytes
In article <4101@awdprime.UUCP> tif@doorstop.austin.ibm.com (Paul Chamberlain) writes:
>In article <16289@s.ms.uky.edu> kherron@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@ssd.csd.harris.com Harris Computer Systems
uunet!hcx1!brad Fort Lauderdale, FL USA
~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~
Technical Details
Message-ID:
<1452@travis.csd.harris.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!att!pacbell.com!ucsd!usc!samsung!rex!uflorida!travis!bradReferences:
<16289@s.ms.uky.edu> <3726@idunno.Princeton.EDU> <4101@awdprime.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!att!pacbell.com!ucsd!usc!samsung!rex!uflorida!travis!brad From: brad@SSD.CSD.HARRIS.COM (Brad Appleton) Newsgroups: comp.unix.shell Subject: Re: Problem with sh/ksh quoting Message-ID: <1452@travis.csd.harris.com> Date: 2 Nov 90 19:32:48 GMT References: <16289@s.ms.uky.edu> <3726@idunno.Princeton.EDU> <4101@awdprime.UUCP> Sender: news@travis.csd.harris.com Distribution: na Organization: Harris Computers Systems Division, Fort Lauderdale,FL Lines: 40