Query - csh handling of quoted strings
APL Consultant
mckenney at talos.UUCP
Sun Oct 23 05:01:04 AEST 1988
The following is a repost (but only for some of you). The
original article specified 'regional' distribution, which was
apprently extremely limited. Too limited, I assume, since not only
did I not receive any suggestions, I didn't even get any insulting
messages (;-)!
Frank McKenney
-----------------------------------------------------------------
I have been attempting to write a csh script which, among other
things, submits a file to be printed via the 'lpr' command. I have
run into a brick wall on trying to handle the case of
myscript -J "Sample Title" file
and being able to pass the quoted string to 'lpr'. The usual error
looks like the following:
lpr: cannot access Title"
Somewhere along the line, the quoted string is getting split up.
I've been through the local (Ultrix) manuals, the 'man' pages,
and Anderson and Anderson's C Shell Field Guide, and I have
received advice and suggestions from a number of local experts,
but to no avail.
Even though my asbestos underwear is currently at the cleaners,
I'm willing to suffer a number of slings and arrows, as well as
the possibility of being pointed out as a total illiterate, in
order to get a solution.
Frank McKenney (who else would WANT my opinions?)
---- script a ------------
#!/bin/csh
#
set lprargs = ""
set file = ""
#--- Shift through command line parameters, one by one.
while ( $#argv != 0 )
switch( $argv[1] )
#
case -[1-4izCJPT#]: # handle args of the form: -x value
set lprargs = ($lprargs $argv[1] \"$argv[2]:q\")
shift # (extra shift)
breaksw
case -*: # handle args of the form: -xvalue
set lprargs = ($lprargs $argv[1])
breaksw
default: # no leading dash: file name
set file = ($file $argv[1])
breaksw
endsw
shift # advance to next argument
end # while $#argv
# Show arguments
echo "lprargs=[$#lprargs]={$lprargs}"
b "$file" "$lprargs:q"
echo lpr "$lprargs" $file
# dummy version for testing - just feeds input file to pipe
cat $file | lpr $lprargs
#
---- script b - show what lpr is getting --
#!/bin/csh
echo "Parameters: $#argv"
foreach p ($argv)
echo "{$p} "
end
#
---- sample run --
cyclops:3> a -J "Another Title" x
lprargs=[2]={-J "Another Title"}
Parameters: 2 <-- (odd, since
{x} foreach finds four!)
{-J}
{"Another}
{Title"}
lpr -J "Another Title" x
x: No such file or directory
lpr: cannot access Title" <--- Broken quoted string.
cyclops:4>
--------------------------------------------------------
Frank McKenney, President | {uunet,rti}!talos!mckenney
McKenney Associates |
3464 Northview Place | guest account - access
Richmond, Virginia 23225 | provided as a courtesy by
USA (804) 320-4887 | Philip Morris USA
---------------------------------------------------------
More information about the Comp.unix.questions
mailing list