Problem with sh/ksh quoting

Kenneth Herron kherron at ms.uky.edu
Wed Oct 31 14:14:42 AEST 1990


I'm having a problem with quoting in shell scripts, exemplified by
the following:

line="this is 'a test'"

for word in $line
do
	echo $word
done

I *want* it to produce:
this
is
a test

but it produces:
this
is
'a
test'

I've tried some variations:
line='this is ''a test'''

line="this is \'a test\'"

temp='a test'
line="this is $temp"

temp='a test'
line="this is '$temp'"

and so on, but either the final set of quotes are stripped out, or not
recognized (as above), or the temp variable isn't expanded, or just about
anything but what I want.  Eval didn't seem to help, nor did quoting the
space within 'a test'.  Does anyone know how to accomplish this?

(BTW, what I'm REALLY trying to do is set options to a command (less) 
where one of the options (the -P prompt option) takes an argument with
spaces.)

Kenneth Herron



More information about the Comp.unix.shell mailing list