- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Posix Shell: shell variable evaluation
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2003 06:01 AM
06-24-2003 06:01 AM
line in the Posix shell. Example ...
$ a=1
$ echo $a
1
$ b=a
$ echo $b
a
I want to evaluate b so that it returns 1.
Something like
echo $($b) --returns--> 1
This way a change to "a" is reflected when evaluating b. If we now change "a" to "a=2" then evaluating b will now return 2.
Please do not suggest "b=$a" that changes the problem.
Pleae no perl solutions.
Thanks,
Pete
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2003 06:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2003 06:10 AM
06-24-2003 06:10 AM
Re: Posix Shell: shell variable evaluation
/tmp> a=b
/tmp> b=1
tmp> eval echo \$$a
1
/tmp>
Best regards ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2003 06:10 AM
06-24-2003 06:10 AM
Re: Posix Shell: shell variable evaluation
Try this:
# eval echo $`echo $b`
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2003 06:16 AM
06-24-2003 06:16 AM
Re: Posix Shell: shell variable evaluation
another solution in order to avoid "\", and
that can be used directly in a script:
#a=1
#b=a
#echo $(($b))
1
#a=2
#echo $(($b))
2
cheers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2003 06:17 AM
06-24-2003 06:17 AM
Re: Posix Shell: shell variable evaluation
eval constructs a command by concatenating args(s) together, separating each with a space. ksh then reads and executes this command in the current environment. Note that command words are expanded twice; once to construct arg and again when ksh executes the constructed command.
an example
foo=10; x=foo
y='$'$x
print $y
$foo
eval y='$'$x
print $y
10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2003 08:04 AM
06-24-2003 08:04 AM
Re: Posix Shell: shell variable evaluation
Not to take anything away from any of the answers but I liked Bruno's the best and was able to use incorporate the concept in my script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2003 08:13 AM
06-24-2003 08:13 AM
Re: Posix Shell: shell variable evaluation
Be careful ... It doesn't work !
#a=1
#b=a
#echo $(($b))
1
#a=2
#echo $(($b))
2
#a="it doesn't work"
#echo $(($b))
sh: it doesn't work: Syntax error
#eval echo \$$b
it doesn't work
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2003 10:36 AM
06-24-2003 10:36 AM
Re: Posix Shell: shell variable evaluation
man -M /usr/dt/man ksh
% typeset -n b=a
% a=1
% echo $b
1
% a=3
% echo $b
3
% b=5
% echo $a
5
% typeset +n b
% echo $b
a
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2003 05:57 AM
07-01-2003 05:57 AM
Re: Posix Shell: shell variable evaluation
I found out rigth away that you are correct.
As you probably realized, I had posted a simplified version of my issue.
I ended up using what you and Massimo posted.
eval echo \$$b
Once again thanks everyone.