Assigning evaluated expression to a variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Assigning evaluated expression to a variable
# 1  
Old 07-21-2008
Assigning evaluated expression to a variable

Hello,

Could you please let me know what is the problem here..
28:var1="SERVER_$j"
29:eval $var1=`grep "^DBSERVER=" "$i" |cut -d"=" -f2`

i get this error:

syntax error at line 29 : `|' unexpected

Thanks for your quick response..This is urgent..pls..

Regards
Kaushik
# 2  
Old 07-21-2008
Sorry, have no working solution yet - can't delete my post, sorry Smilie

Last edited by zaxxon; 07-21-2008 at 10:43 AM..
# 3  
Old 07-21-2008
That should hopefully work - tested it on some similar example.

Code:
var1="SERVER_$j"
TMP_VAR="`grep "^DBSERVER=" "$i" |cut -d"=" -f2`"
eval ${var1}="${TMP_VAR}"

# 4  
Old 07-22-2008
It still does not work...Does it have to do something with the filename being conatined in the variable i?
# 5  
Old 07-22-2008
Code:
 
#!/usr/bin/bash
i=test.txt
j=B10
var1=SERVER_"$j"
echo "DBSERVER = $var1"
eval var1=`grep "^DBSERVER=" "$i" | cut -d"=" -f2`
echo "DBSERVER = $var1"

With file test.txt containing:
Code:
 
line 1
 DBSERVER=SERVER_XXX
line 3
DBSERVER=SERVER_A1
line 5

Produces the following when run:
Code:
 
HOSTNAME:> test.sh
DBSERVER = SERVER_B10
DBSERVER = SERVER_A1

# 6  
Old 07-22-2008
Thanks folks..Problem got resolved..there was a mismatching '`' above the mentioned lines of code which was causing the problem..

Thank you...
Regards
Kaushik
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Assigning an expression to a variable in shell script

i am trying to assign the following expression to a variable in Unix shell script and want to use that variable in some other expression. But unable to get the required thing done. Please help with this.... This is the expression which i want to provide as input the variable date '+%y:%m:%d' |... (3 Replies)
Discussion started by: ssk250
3 Replies

2. Shell Programming and Scripting

Assigning a value to a variable

Hi I have a script that accepts an input date in YYYY-MM-DD format. After that, I used sed to delete the hyphen (-) which gives me an output YYYY MM DD. My question is, how can I assign those three numbers to a three different variable. Example: 2013-11-23 will become 2013 11 23... (4 Replies)
Discussion started by: erin00
4 Replies

3. Shell Programming and Scripting

assigning value of a expression to a variable

eval echo \$tts_space_name$count i m getting output of this stmnt as 'TBS_ADOX_EXTR3' but, I m not able to assign this value to a variable . i tried export j=`eval echo \$tts_space_name$count` eval j= `eval echo \$tts_space_name$count` and when i do echo $j ... i get o/p as 1 or 2... (1 Reply)
Discussion started by: Gl@)!aTor
1 Replies

4. Shell Programming and Scripting

problem in assigning value to variable have value fo other variable

my script is some thing like this i11="{1,2,3,4,5,6,7,8,9,10,11,}" echo "enter value" read value ..............suppose i11 x="$value" echo "$($value)" .............the echo should be {1,2,3,4,5,6,7,8,9,10,11,} but its showing "i11" only. plz help me out to get desired... (10 Replies)
Discussion started by: sagar_1986
10 Replies

5. Shell Programming and Scripting

Assigning expression value to tcsh variables

Hi All, I have a tcsh script as: #!/usr/bin/csh -x set packsName=$(awk -F'' '/^execute.*=true/{print $2}' ExecutePacks.config) for var in $packsName do echo "printed $var" done I want to assign the value which is returned by awk function to the variable called packsName. How do I... (2 Replies)
Discussion started by: AB10
2 Replies

6. Shell Programming and Scripting

Variable is not evaluated in awk statement

Dear All, I have one problem in my script, awk statement as 1. it is not evaluate the second variable $stake but the first one $channel is being done. 2.I want to assign the whole awk statement to a variable actual_code which is not being executed in my script. #!/usr/bin/sh echo "Enter... (3 Replies)
Discussion started by: chinmayadalai
3 Replies

7. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

8. Shell Programming and Scripting

Assigning value to a variable

Is there any difference between: set variable=39 and variable=39 (1 Reply)
Discussion started by: proactiveaditya
1 Replies

9. Shell Programming and Scripting

assigning a variable

hi all, in ksh, how do i assign the output of a find command to a variable, e.g am trying something like this : totalNoFiles=$(print find ./ -name "SystemOut*.log"); but when i echo $totalNoFiles it displays find ./ -name "SystemOut*.log" instead of the total number of... (2 Replies)
Discussion started by: cesarNZ
2 Replies

10. Shell Programming and Scripting

Assigning a value to variable

Another newbie to Unix scripting Q.. How do you assign a value resulting from a command, such as awk, to a variable. I am currently trying:- $awk '{print $1}' file1 > variable1 with no change to $variable1. The line: $awk '{print $1}' file1 does print the first line of the... (3 Replies)
Discussion started by: sirtrancealot
3 Replies
Login or Register to Ask a Question