Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] eval a shell variable
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
toralf
Advocate
Advocate


Joined: 01 Feb 2004
Posts: 2104
Location: Hamburg/Germany

PostPosted: Thu Jan 31, 2008 10:36 am    Post subject: [solved] eval a shell variable Reply with quote

I try something like this :
Code:
SQL_FOO="select * from foo"
SQL_BAR="select * from bar"

T="FOO"

RESULTS=`$SQL_$T`
Currently I get obviously not the result set from the DB.
My question is, how can I first create a variable name and after that use the _content_ the variable points to ?


Last edited by toralf on Sun Mar 16, 2008 8:19 pm; edited 1 time in total
Back to top
View user's profile Send private message
Voltago
Advocate
Advocate


Joined: 02 Sep 2003
Posts: 2482
Location: Hinter den Materiequellen

PostPosted: Thu Jan 31, 2008 11:15 am    Post subject: Reply with quote

Code:
myvar=hello
varname=myvar
echo $varname
echo ${!varname}


Oh, and btw:
http://www.tldp.org/LDP/abs/html/
Back to top
View user's profile Send private message
toralf
Advocate
Advocate


Joined: 01 Feb 2004
Posts: 2104
Location: Hamburg/Germany

PostPosted: Thu Jan 31, 2008 12:12 pm    Post subject: Reply with quote

thanks,
unfortunately I have to code this within ksh under IX 5.3 :-(
But this works :
Code:
[tfoerste@detlmtst01] /home/tfoerste> SQL_FOO="select count(id) from adm.agent"
[tfoerste@detlmtst01] /home/tfoerste> T=SQL_FOO
[tfoerste@detlmtst01] /home/tfoerste> eval $(echo db2 \$$T)

1
-----------
      23756

  1 record(s) selected.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum