C-shell script variable substitution problem/question

Jonathan I. Kamens jik at cats.ucsc.edu
Tue Jun 25 15:29:10 AEST 1991


  (Note cross-post and followup-to.)

In article <1991Jun24.230024.18513 at iscnvx.uucp>, wurtz at iscnvx.uucp (J D Wurtz) writes:
|>      1) the executable c-shell script named "sc":
|> 
|>                #!/bin/csh -f
|> 
|>                if ( $1 == "" ) then

I personally would prefer

		if ($#argv < 1 ) then

here.

|>                   echo 'Name of the directory> \c'
|>                   set dir = ($<)
|>                else
|>                   set dir = $1
|>                endif
|> 
|>                cat  $dir/testfile             # display the file
|> 
|> ...
|> 
|>      4) the variable "ilu" is set to "/home/love/you"

Is the variable a shell variable (set with "set") or an environment variable
(set with "setenv")?  If the former, there's no way to do what you want to do,
because the subshell in which the shell script runs has no idea what the
contents of the variable are.

|> ...
|> 
|>      4) sc
|>         Name of the directory> $ilu
|> 
|> Cases 1, 2, and 3 above all work very nicely, doing exactly what I want.
|> Case 4, however, does not work because shell variable "ilu" is not substituted
|> with its value (which is "/home/love/you").
|> 
|> Who can please tell me how to make the c-shell treat variable "ilu" the same
|> for case (4) as it does for case (3)?  Also, is this called "recursive
|> substitution"?  Many thanks for your assistance.

After

		set dir = ($<)

you could add

		set dir = `eval echo $dir`

However, as I said, this will only work if the variable is an environment
variable.

In any case, I don't really know what I'd call what you're trying to do. 
"Repeated evaluation" seems as close as "recursive substitution."  See the man
page for csh for more information about "eval."

-- 
Jonathan Kamens					jik at CATS.UCSC.EDU



More information about the Comp.unix.questions mailing list