Delayed evaluation of csh variables?

Tom Christiansen tchrist at convex.COM
Tue Dec 11 11:24:07 AEST 1990


In article <CHRIS.90Dec10160308 at asylum.gsfc.nasa.gov> chris at asylum.gsfc.nasa.gov (Chris Shenton) writes:
:I'm trying to do a script where I set up a variable to contain a template,
:then later instantiate one of the variables; the whole thing then is passed
:to a command. Something like this, conceptually:
:
:#!/bin/csh

You forgot the -f there.  That'll slow you down a lot and 
could have unforeseen side-effects.

:set COMMAND = "command"
:set OPTION_TEMPLATE = "-Z '$File'"	# Want *literal* $File
:					#   -- to be evaluated *later* --
:					#   but csh evaluates it now and dies
:foreach File ( $* )			# Instantiate in $OPTION_TEMPLATE ??
:	$COMMAND $OPTION_TEMPLATE	# doesn't work
:end

:Is there a way to do this? 

Sure, you could use an eval (we seem to get kind of question one a lot).
One of your problems is using the csh at all.  It's a real pain.  I've
heard Bill Joy will tell you he didn't understand expression evaluation
when he wrong it.  It does show.  You could do this:

    set OPTION_TEMPLATE = '-Z $File'	# Want *literal* $File

and then this:
    eval $COMMAND $OPTION_TEMPLATE	

but please trust me when I tell you that you do not want to be 
writing scripts in csh.  Honest.

--tom
--
Tom Christiansen		tchrist at convex.com	convex!tchrist
"With a kernel dive, all things are possible, but it sure makes it hard
 to look at yourself in the mirror the next morning."  -me



More information about the Comp.unix.shell mailing list