home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!scorn!scolex!charless
- From: charless@sco.COM (charles stross)
- Subject: Re: Echoing Shell Variables
- Organization: The Somewhat Contagious Operation, Inc.
- Date: Wed, 12 Aug 1992 10:46:38 GMT
- Message-ID: <1992Aug12.104638.24076@sco.COM>
- References: <2647@nlsun1.oracle.nl>
- Sender: news@sco.COM (Account for Usenet System)
- Lines: 41
-
-
- In article <2647@nlsun1.oracle.nl> rgasch@nl.oracle.com (Robert Gasch) writes:
- >
- >I have a little problem that's quite annoying. I have written
- >a shell script which receives as it's argument than name of
- >a shell variable (ex: PATH) via $1.
- >
- >The big question is: How can I echo the contents of the variable
- >whose name I get? For example: If $1 contains the string PATH,
- >I want to be able to do the equivalent of saying "echo $PATH" at
- >the command prompt so that I receive a list of directories
- >which are in the path.
- >
- >For some reason I can't figure this one out. The only thing
- >I've been able to get is PATH (the contents of the argument)
- >and errors.
- >
- >Any help on this will be much appreciated
- >---> Rob
- >
-
- Try this:
-
- #!/bin/ksh
- eval echo \$$1
-
- (It works for me :)
-
- Attempted explanation:
-
- The eval command reads and executes the Korn shell command line that
- follows it. You use it to induce the shell to scan the command line
- twice before executing it. On the first pass, the shell replaces \$
- with a literal $ and expands $1 (say, PATH). On the second pass it
- sees the command echo $PATH.
-
- --
- Charlie Stross aka charless@scol.sco.com
- UNIX-oriented text mangler
- This 'ere is my opinion;
- now't t'do wi' SCO.
-