home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3470 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  1.5 KB

  1. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!mips!swrinde!elroy.jpl.nasa.gov!news.claremont.edu!ucivax!cigna!nagel
  2. From: nagel@Cigna.COM (Mark Nagel)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: unwinding $variables in csh
  5. Keywords: resolve, unwind $variables, csh
  6. Message-ID: <1992Aug12.230438.20870@Cigna.COM>
  7. Date: 12 Aug 92 23:04:38 GMT
  8. References: <1992Aug9.194325.1476@sol.UVic.CA>
  9. Sender: news@Cigna.COM (Network News)
  10. Organization: CIGNA FIRST, Irvine, CA
  11. Lines: 37
  12. Nntp-Posting-Host: orwell
  13.  
  14. In <1992Aug9.194325.1476@sol.UVic.CA> stilley@csr.UVic.CA (Scott  Tilley) writes:
  15.  
  16. >What is the easiest way to completely resolve variables in csh? I have
  17. >several variables that are made up of other $variables. I do not
  18. >want them expanded until the end of the script, so I use
  19.  
  20. >    set var1 = '$HOME'
  21. >    set var2 = '$var1/dir'
  22.  
  23. >for example. At the end of the script I need to propagate var2 to the
  24. >environment, such as
  25.  
  26. >    setenv DIR $var2
  27.  
  28. >but this produces "$DIR = $HOME/dir", i.e., $HOME does not
  29. >get expanded. How can I get csh to fully expand all variables
  30. >in one shot?
  31.  
  32. Try using eval:
  33.  
  34. #! /bin/csh -f
  35.  
  36. set var1 = '$HOME'
  37. set var2 = '$var1/dir'
  38. echo "var1 = $var1"
  39. echo "var2 = $var2"
  40. setenv DIR $var2
  41. echo "DIR = $DIR"
  42. eval setenv DIR $var2
  43. echo "eval'ed DIR = $DIR"
  44. eval eval setenv DIR $var2
  45. echo "eval'ed eval'ed DIR = $DIR"
  46. -- 
  47. Mark Nagel <nagel@cigna.com>    | DISCLAIMER: Any resemblence of these
  48. Network Administrator        | opinions to those of CIGNA are purely
  49. CIGNA/FIRST            | coincidental.
  50.           (Don't start vast projects with half-vast ideas)
  51.