[comp.unix.wizards] csh and globbing in `..`

shankar@hpclscu.HP.COM (Shankar Unni) (03/11/88)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%   YACW (Yet Another Csh Weirdness). %%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I'm trying to set a shell variable to contain the output of a command.

For instance,

   set myvar = `grep 'Compile' RESULTS`

This is what happens:

   % ls
   RESULTS bar bletch foo
   % grep 'Compile' RESULTS
   * Compile successful
   % set line = `grep Compile RESULTS`
   % echo $line
   RESULTS bar bletch foo Compile successful

   (!!)

Actually, I sort of understand (I think) what's going on here. The `` globs
the *. OK, OK. Now, how do I disable this globbing?

I've tried:
   % grep .. > /tmp/XXX
   % set line = `cat /tmp/XXX`
with the same results (obviously, as I see now..)

I finally had to do something gross like creating an awk script like
   {print "set line='" $0 "'"}

and try

   grep .. | awk -f awkscript > /tmp/YYY
   source /tmp/YYY

   (AAARGH!!)

Is there an easier (and more elegant) way to do this? I also tried setting
noglob (which was calmly ignored by the ``), so *that*'s not the answer
either..

(Almost makes me want to switch to "ksh" Hahhahhahhehheh..errr..)

ADVthanksANCE,
Shankar.

enag@ifi.uio.no (03/13/88)

Shankar Unni <shankar@hpclscu.HP.COM> has a problem with file globbing
within ``.  Actually, the problem is not within ``.  It is the order In
which the the command line is interpreted that is your problem.  In
csh, the `` is obviously parsed and executed before file names are
globbed.  Thus there is no difference between

	echo * foo bar
and	echo `grep foo zot`

if "grep foo zot" says "* foo bar".

There should, therefore, be no difference between

	echo "* foo bar"
and	echo "`grep foo zot`"

either, given the above match for foo.

I think this has solved your problem, Shankar, unless, of course, you
want "line" after

	set line = "`grep Compile RESULTS`"

to be a list of three elements, instead of one element with embedded
spaces, which is what this will give you.

By the way, the csh I occasionally use here at the University of Oslo
SunOS 3.4EXPORT installation does behave correctly (or, as you want it
to) when I set noglob.  (I did not find any version information in
/bin/csh.  It might have come with SunOS 3.2 or 3.3.)

Erik Naggum
ARPA:	enag@ifi.uio.no (or erik%naggum.uucp@ifi.uio.no)
UUCP:	erik@naggum.se	(or ...!uunet!naggum!erik)
FONE:	+47-2-384-800 (work), +47-2-549-163 (home)
MAIL:	Naggum Software, POB 1560 VIKA, 0118 OSLO, NO(R)WAY

shankar@hpclscu.HP.COM (Shankar Unni) (03/15/88)

I've received several replies, many of which pointed me in the right direction.
The solution was to put the `..` inside double quotes.

   set line = "`...`"
   echo "$line"

Thanx again to all who took the trouble to reply.

Shankar.