home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!paladin.american.edu!darwin.sura.net!mips!swrinde!elroy.jpl.nasa.gov!news.claremont.edu!ucivax!cigna!nagel
- From: nagel@Cigna.COM (Mark Nagel)
- Newsgroups: comp.unix.shell
- Subject: Re: unwinding $variables in csh
- Keywords: resolve, unwind $variables, csh
- Message-ID: <1992Aug12.230438.20870@Cigna.COM>
- Date: 12 Aug 92 23:04:38 GMT
- References: <1992Aug9.194325.1476@sol.UVic.CA>
- Sender: news@Cigna.COM (Network News)
- Organization: CIGNA FIRST, Irvine, CA
- Lines: 37
- Nntp-Posting-Host: orwell
-
- In <1992Aug9.194325.1476@sol.UVic.CA> stilley@csr.UVic.CA (Scott Tilley) writes:
-
- >What is the easiest way to completely resolve variables in csh? I have
- >several variables that are made up of other $variables. I do not
- >want them expanded until the end of the script, so I use
-
- > set var1 = '$HOME'
- > set var2 = '$var1/dir'
-
- >for example. At the end of the script I need to propagate var2 to the
- >environment, such as
-
- > setenv DIR $var2
-
- >but this produces "$DIR = $HOME/dir", i.e., $HOME does not
- >get expanded. How can I get csh to fully expand all variables
- >in one shot?
-
- Try using eval:
-
- #! /bin/csh -f
-
- set var1 = '$HOME'
- set var2 = '$var1/dir'
- echo "var1 = $var1"
- echo "var2 = $var2"
- setenv DIR $var2
- echo "DIR = $DIR"
- eval setenv DIR $var2
- echo "eval'ed DIR = $DIR"
- eval eval setenv DIR $var2
- echo "eval'ed eval'ed DIR = $DIR"
- --
- Mark Nagel <nagel@cigna.com> | DISCLAIMER: Any resemblence of these
- Network Administrator | opinions to those of CIGNA are purely
- CIGNA/FIRST | coincidental.
- (Don't start vast projects with half-vast ideas)
-