quoting variables in csh - bug in certain implementation
Phil Howard KA9WGN
phil at ux1.cso.uiuc.edu
Fri Mar 1 07:04:27 AEST 1991
I have run into a bug with one implementation of csh that appears to be
related to variable quoting, or the lack thereof, but with a peculiar
side effect as well. I would like comments, especially from those who
understand the internals of csh (I don't).
[text pasted in from other windows is indented with "> "]
On system 1 (the OK one) I get these expected results:
> phil at ux1:/cso/staff/phil 7>
> phil at ux1:/cso/staff/phil 7> set awk = 'BEGIN{w=h=d="?"}\
> /Width:/{w=$3}\
> /Height:/{h=$3}\
> /Depth:/{d=$3}\
> END{print "set width =",w,";set height =",h,";set depth =",d}'
> phil at ux1:/cso/staff/phil 8>
> phil at ux1:/cso/staff/phil 8> echo $awk
> Missing }.
> phil at ux1:/cso/staff/phil 9>
> phil at ux1:/cso/staff/phil 9> echo $awk:q
> BEGIN{w=h=d="?"}
> /Width:/{w=$3}
> /Height:/{h=$3}
> /Depth:/{d=$3}
> END{print "set width =",w,";set height =",h,";set depth =",d}
> phil at ux1:/cso/staff/phil 10>
> phil at ux1:/cso/staff/phil 10> echo "${awk:q}"
> BEGIN{w=h=d="?"
> /Width:/{w=$3
> /Height:/{h=$3
> /Depth:/{d=$3
> END{print "set width =",w,";set height =",h,";set depth =",d}
> phil at ux1:/cso/staff/phil 11>
> phil at ux1:/cso/staff/phil 11>
However on system 2 (the bad one) I get some strange results:
> pdh at spiff:/home/fsg/pdh 44>
> pdh at spiff:/home/fsg/pdh 44> set awk = 'BEGIN{w=h=d="?"}\
> /Width:/{w=$3}\
> /Height:/{h=$3}\
> /Depth:/{d=$3}\
> END{print "set width =",w,";set height =",h,";set depth =",d}'
> pdh at spiff:/home/fsg/pdh 45>
> pdh at spiff:/home/fsg/pdh 45> echo $awk
> Missing }.
> pdh at spiff:/home/fsg/pdh 46>
> pdh at spiff:/home/fsg/pdh 46> echo $awk:q
> Missing }.
> pdh at spiff:/home/fsg/pdh 47>
> pdh at spiff:/home/fsg/pdh 47> echo "${awk:q}"
> Unmatched ".
> pdh at spiff:/home/fsg/pdh 48>
> /Width:/{w=}?
> /Height:/{h=}?
> /Depth:/{d=}?
> END{print? ?"set? width? =?",w,?"?;set? height? =?",h,?"?;set? depth? =?",d}: Ambiguous.
> pdh at spiff:/home/fsg/pdh 49>
> pdh at spiff:/home/fsg/pdh 49>
Note that at prompt number 48 I simply pressed carriage return. It appears to
me that it had for some reason (because newline characters are in the
variable?) it placed data in a buffer, or left it in a buffer incorrectly.
The portion of the output of the "set" command showing the contents of the
variable "awk" are: [indented with "> "]
> awk BEGIN{w=h=d="?"}
> /Width:/{w=$3}
> /Height:/{h=$3}
> /Depth:/{d=$3}
> END{print "set width =",w,";set height =",h,";set depth =",d}
So their are definitely some newlines in there.
I have been experimenting with another problem on the same system and noted
some effects related to the above that indicate a problem in the quoting.
In this other problem, backquotes work on "set" and fail on "setenv":
> pdh at spiff:/home/fsg/pdh 55> set date = `date`
> pdh at spiff:/home/fsg/pdh 56>
> pdh at spiff:/home/fsg/pdh 56> echo $date
> Thu Feb 28 14:53:44 EST 1991
> pdh at spiff:/home/fsg/pdh 57>
> pdh at spiff:/home/fsg/pdh 57> setenv DATE `date`
> `date`: Ambiguous.
> pdh at spiff:/home/fsg/pdh 58>
> pdh at spiff:/home/fsg/pdh 58> echo $DATE
> DATE: Undefined variable.
> pdh at spiff:/home/fsg/pdh 59>
> pdh at spiff:/home/fsg/pdh 59> setenv DATE $date:q
> setenv: Too many arguments.
> pdh at spiff:/home/fsg/pdh 60>
> pdh at spiff:/home/fsg/pdh 60> setenv DATE "${date:q}"
> pdh at spiff:/home/fsg/pdh 61>
> pdh at spiff:/home/fsg/pdh 61> echo $DATE
> 28 Thu Feb EST EST 1991
> pdh at spiff:/home/fsg/pdh 62>
> pdh at spiff:/home/fsg/pdh 62>
Note the result of the command at prompt 59.
Comments? Ideas? Suggestions? This is not a problem critical to me because
I use that system for nothing more than testing for just such portability
problems. But of course finding ways to make programs work on more machines
by getting broken ones fixed, fixing my own programs, or just finding a
good workaround, is always desireable.
Thanks!
phil-howard at uiuc.edu
--
--Phil Howard, KA9WGN-- | Individual CHOICE is fundamental to a free society
<phil at ux1.cso.uiuc.edu> | no matter what the particular issue is all about.
More information about the Comp.unix.shell
mailing list