C-shell script variable substitution problem/question

J D Wurtz wurtz at iscnvx.uucp
Tue Jun 25 09:00:24 AEST 1991


I like scripts that are "forgiving", i.e., if I forget to supply an argument,
I want the script to automatically prompt me for the missing information.
I've run into a problem, however.  Given the following:

     1) the executable c-shell script named "sc":

               #!/bin/csh -f

               if ( $1 == "" ) then
                  echo 'Name of the directory> \c'
                  set dir = ($<)
               else
                  set dir = $1
               endif

               cat  $dir/testfile             # display the file

     2) I'm currently in directory "/home/love"

     3) the file named "testfile" is located in directory "/home/love/you"

     4) the variable "ilu" is set to "/home/love/you"

     5) IRIX System V Release 3.3.2.

I then type the following to execute script "sc" in four different ways:

     1) sc /home/love/you

     2) sc
        Name of the directory> /home/love/you

     3) sc $ilu

     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.
-- 
Jeffrey D. Wurtz, Staff Engineer            wurtz at sgi421.msd.lmsc.lockheed.com
Structures, Orgn/81-12, Bldg/157                      (408)756-1377
Lockheed Missiles and Space Company, Inc.
Sunnyvale, CA  94088-3504



More information about the Comp.unix.questions mailing list