![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| pass variable from awk to shell script | user_prady | Shell Programming and Scripting | 3 | 04-17-2008 05:43 AM |
| How to pass Shell script variable to awk | HIMANI | UNIX for Dummies Questions & Answers | 3 | 07-16-2007 12:23 AM |
| transfer a variable in a shell script? | fedora | Shell Programming and Scripting | 11 | 09-22-2006 12:56 PM |
| How to Pass variable to shell Script | sam70 | UNIX for Dummies Questions & Answers | 5 | 08-23-2005 07:27 PM |
| passing awk variable to the shell script | bcheaib | Shell Programming and Scripting | 3 | 07-21-2004 10:00 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
hi all,
i want use the variable value as a new variable name. And i want to use this new variable value for i in COMPUTER1 COMPUTER2 do flag_name=${i}_FLAG eval ${flag_name}=123 echo $i'_FLAG' done output is COMPUTER1_FLAG COMPUTER2_FLAG i need output as 123 |
|
||||
|
You need an eval around the echo too. And a literal dollar sign in front of the variable.
Code:
eval echo \$${i}_FLAG
|
|
||||
|
having problem with if condiation
hi era,
your given code (eval echo \$${i}_FLAG) is woking fine. now i want to use the variable value to in if condiation.. is following code is right. please help for i in COMPUTER1 COMPUTER2 do flag_name=${i}_FLAG eval ${flag_name}=1 if [ `eval echo \$${i}_FLAG` -eq 1 ] then echo yes else echo no fi done |
|
||||
|
With the backticks, you will be requiring even more backslashes. But I'd recommend against using backticks, and "if test -eq".
Code:
eval 'case $'${i}'_FLAG in 1) echo yes;; *) echo no;; esac'
Last edited by era; 08-07-2008 at 02:24 AM.. Reason: Oops, fix quoting |
![]() |
| Bookmarks |
| Tags |
| eval, variable name from variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|