Problem with csh;request for fix (LONG)
Mark E. Sunderlin
megabyte at chinet.UUCP
Tue Jul 8 01:00:50 AEST 1986
(Feel free to s/bug/problem/ throughout this article)
Ok my fellow unix-wizards, I have come across a bug(?) I can't understand. It
seems that csh can't deal with variable assignment when the value to assign
to the variable has the meta characters [] or {} in it. However it seems
that the bourne shell has no problems with it. Reproduce with the following
transcript of a csh session. My own comments are in ()'s and are not
part of the xscript:
----------------------------------------------------------------------
1% set fix = "string[67]"
2% set
argv ()
fix string[67]
(^^^^^^^^^^^^^^^^^ OK, the value IS in the variable)
history 21
home /z11/sunder
logname sunder
mail /usr/spool/mail/sunder
path (. /bin /usr/bin /z/informix3.3 /z/universal /z/bin /z11/sunder/bin )
prompt !%
shell /bin/csh
status 0
term d1
tz EST5EDT
3% echo $fix
echo: No match.
(^^^^^^^^^^^^^^ but csh trys to expand the [67] somehow)
4% sh
(^^^^^^ Now we go to the bourne shell)
$ fix="string[67]"
$ set
HOME=/z11/sunder
IFS=
IGNOREEXIT=1
LOGNAME=sunder
MAIL=/usr/spool/mail/sunder
PATH=:/bin:/usr/bin:/z/informix3.3:/z/universal:/z/bin:/z11/sunder/bin:
SHELL=/bin/csh
TERM=d1
TZ=EST5EDT
fix=string[67]
(^^^^^^^^^^^^^ Value is in there fine)
$ echo $fix
string[67]
(^^^^^^^^^ and it echos without problems of expansion)
5% echo "$fix"
( ^^^^^^^^ a way aroung this trivial example)
string[67]
6%
---------------------------------------------------------------------------
I always considered this a trivial problem with csh (and one more reason why I
use sh or ksh) until a user on my system showed me the following problem. He
was trying to set a variable equal to the output of a grep statement in which
the lines he was grepping for had [] characters in them. Here is
a transcript of his attempt,again with my comments in ()'s:
----------------------------------------------------------------------------
1% cat fix10
( ^^^^^^ a subset of his orignal "C" program he was grepping)
#define key_f10 CUR Strings[67]
#define key_f2 CUR Strings[68]
#define key_f3 CUR Strings[69]
#define key_f4 CUR Strings[70]
#define key_f5 CUR Strings[71]
#define key_f6 CUR Strings[72]
#define key_f7 CUR Strings[73]
#define key_f8 CUR Strings[74]
#define key_f9 CUR Strings[75]
#define key_home CUR Strings[76]
2% set fix = `grep define fix10`
3% echo $fix
#define key_f10 CUR #define key_f2 CUR #define key_f3 CUR #define key_f4 CUR
( ^^^^ All the [##]'s are gone!!!!)
#define key_f5 CUR #define key_f6 CUR #define key_f7 CUR #define key_f8 CUR #
define key_f9 CUR #define key_home CUR
4% sh
( ^^^ now we go to the bourne shell)
$ fix=`grep define fix10`
$ echo $fix
#define key_f10 CUR Strings[67] #define key_f2 CUR Strings[68] #define key_f3
( ^^^^ Works under bourne)
CUR Strings[69] #define key_f4 CUR Strings[70] #define key_f5 CUR Strings[71
] #define key_f6 CUR Strings[72] #define key_f7 CUR Strings[73] #define key_f
8 CUR Strings[74] #define key_f9 CUR Strings[75] #define key_home CUR Strings
[76]
5%
---------------------------------------------------------------------------
The same behavior happens with the {} char in a file also. The <> chars pass
through csh ok. Here is what I want to know: I think I understand WHY this
is going on, it's just a bug(?) in csh(If I'm wrong, let me know). The real
question is, is there a way around this, so that the variable is set to
the actual grep output rather than having the metacharacters striped out?
Comments to the effect of "Just use the Bourne shell" will fall on
sympathetic ears on my part but will cause great unrest among my users.
For the record: I use running ZEUS 3.21 on a Zilog model 31. ZEUS, for those of
you fortunate to have not dealt with it is a SYSIII port with a few Berkley
tools (csh,vi,more,etc) thrown in. I'm not sure which versions of sh and csh
Zilog used, as I have no way to relate them to the BSD or USG revision numbers.
The opinions expressed herein are my own and do not reflect those of
the Internal Revenue Service or any other agency of the United States
Government. (A US Gov't disclaimer produced for the protection of the
taxpayers from their fellow taxpayers)
--
_________________________________________________________________________
UUCP: (1) seismo!why_not!scsnet!sunder Mark E. Sunderlin
(2) ihnp4!chinet!megabyte aka Dr. Megabyte
CIS: 74026,3235 (202) 634-2529
Quote: "I drank what? " - Socrates (9-4 EDT)
Mail: IRS 1111 Constitution Ave. NW PM:PFR:D:NO Washington, DC 20224
More information about the Comp.unix.wizards
mailing list