The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
bash shell: 'exec', 'eval', 'source' - looking for help to understand alex_5161 Shell Programming and Scripting 3 07-24-2008 12:42 PM
c shell scripting bigboizvince Shell Programming and Scripting 1 03-25-2008 09:33 AM
Shell scripting sreejith SUN Solaris 2 10-08-2006 09:38 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM
shell scripting anuradr Shell Programming and Scripting 1 03-08-2006 06:22 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-22-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You should probably start a new thread for an unrelated question anyway.
  #2 (permalink)  
Old 06-25-2009
wumpus wumpus is offline
Registered User
  
 

Join Date: Jun 2009
Location: St. Louis, MO, USA
Posts: 2
How to save eval output

/bin/sh$ var=foo
/bin/sh$ foo=bar
/bin/sh$ eval echo \${$var}
bar
/bin/sh$ val=`eval echo \${$var}`
bad substitution

How can I save the output of eval echo \${$var} to a variable?

Thanks.
  #3 (permalink)  
Old 06-25-2009
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by wumpus View Post
/bin/sh$ var=foo
/bin/sh$ foo=bar
/bin/sh$ eval echo \${$var}
bar
/bin/sh$ val=`eval echo \${$var}`
bad substitution

How can I save the output of eval echo \${$var} to a variable?

Thanks.

Maybe something like this:


Code:
$ var=foo

$ foo=bar

$ set -x

$ cmd='eval echo \${$var}'
+ cmd='eval echo \${$var}'

$ val=$(eval $cmd)
++ eval eval echo '\${$var}'
+++ eval echo '${foo}'
++++ echo bar
+ val=bar

$ echo $val
+ echo bar
bar
  #4 (permalink)  
Old 06-25-2009
wumpus wumpus is offline
Registered User
  
 

Join Date: Jun 2009
Location: St. Louis, MO, USA
Posts: 2
Quote:
Originally Posted by rubin View Post
Maybe something like this:


Code:
$ var=foo

$ foo=bar

$ set -x

$ cmd='eval echo \${$var}'
+ cmd='eval echo \${$var}'

$ val=$(eval $cmd)
++ eval eval echo '\${$var}'
+++ eval echo '${foo}'
++++ echo bar
+ val=bar

$ echo $val
+ echo bar
bar
That works for Korn shell, but I was looking for a Bourne shell solution.

---------- Post updated at 01:24 PM ---------- Previous update was at 01:11 PM ----------

/bin/sh$ var=foo
/bin/sh$ foo=bar
/bin/sh$ val=`eval echo \\$\${var}`
/bin/sh$ echo ${val}
bar

Thank you Ken!
Reply

Bookmarks

Tags
bash, bash eval, eval

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0