New Variable with Existing variable( Urgent)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers New Variable with Existing variable( Urgent)
# 1  
Old 08-07-2008
New Variable with Existing variable( Urgent)

hi all,

i want use the variable value as a new variable name. print output of new variable.


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
123
# 2  
Old 08-07-2008
Try using shell indirect reference.

- nilesh
# 3  
Old 08-08-2008
Hi Aravind,

Basically eval can be used only for manipulating some numbers , i think u can use just a

variable assignment....

$\{flag_name\}=123

Kindly try this and send output...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Not able to assign 0 (zero) to the existing variable

Hi, I have a variable which read the value from the lines, and if it is empty string (5 bytes), then I have to assign this variable to zero "0", it able to detect the data is empty by showing me the message "empty", but not able to assign it as zero. WTHP=`echo "$file" | cut -c158-162` if ]... (5 Replies)
Discussion started by: newbie2011
5 Replies

2. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

3. UNIX for Dummies Questions & Answers

creating a new variable from existing data

Hello, I have the following data set: TRAIT DOSE 40 0.4 30 0.3 95 1.2 120 1.7 85 1.4 136 1.8 134 1.8 40 0.4 30 0.3 95 1.2 120 1.7 85 1.4 136 1.8 134 1.8 40 0.4 30 0.3 95 1.2 (2 Replies)
Discussion started by: wolf_blue
2 Replies

4. Shell Programming and Scripting

Change existing variable value only user enters non-empty string.

I haven't checked any installation script to see how this is done.. But I could not even do following simple task. How do I Change existing variable value only when user enteres non-empty string. ? #!/usr/bin/ksh uid="scott" # Assign new value user enters to uid, else leave it... (7 Replies)
Discussion started by: kchinnam
7 Replies

5. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

6. Shell Programming and Scripting

if condition for variable existing in file

Hi, Sorry for the dumb question but I can't seem to figure this one out. I want to write an if condition that basically checks if my variable is in a file. So far I have the following: if ] then do something else do something else fi So essentially if the grep returns something then... (3 Replies)
Discussion started by: eltinator
3 Replies

7. UNIX for Advanced & Expert Users

Urgent-reading a variable value

Hi, I have a text file in which , I have contents like t1=abc t2=xyz t3=awe ...... I am able to read contents of these variables in a script by . /temp.txt echo $t1 Now, what my requirement is something like this a="t" i=1 echo $a$i --->this is displaying t1 (3 Replies)
Discussion started by: kaaakrishna
3 Replies

8. UNIX for Advanced & Expert Users

Urgent-Reading eval result in a variable

Hi everyone, I do have the requirement to store the value of below result in a variable eval echo $a Please .... Help me , it's urgent to my sript Thanks in advance... (1 Reply)
Discussion started by: kaaakrishna
1 Replies

9. Shell Programming and Scripting

how to store the first content of the folder in a variable?(Urgent)

Hi All, I need urgent help. Because just now i have to give this code to my client. I have a folder name is Testing. this Testing folder contains the following 3 files. 1.txt 2.txt 2.txt Now I want to store the first value of my folder in a variable say suppose $a. Means i want that... (3 Replies)
Discussion started by: sunitachoudhury
3 Replies

10. Shell Programming and Scripting

Urgent!! Bash - problem using CD with variable

I am extracting directory path from file which is stored in a variable. while read inputline do script_name=`echo $inputline | cut -d' ' -f2` cd $script_name done < path_scripts.txt where as path_scripts contains input_process.bash ~/jobs/process/input/bin The script output says... (1 Reply)
Discussion started by: jacksam007
1 Replies
Login or Register to Ask a Question