Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sundc!texsun!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.shell Subject: Re: Delayed evaluation of csh variables? Message-ID: <110255@convex.convex.com> Date: 11 Dec 90 00:24:07 GMT References: Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 38 In article chris@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@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