Visit Our UNIX and Linux User Community


Unable to get the Value of variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to get the Value of variable
# 1  
Old 06-03-2011
Unable to get the Value of variable

Hi,
I have a properties file that is read by the Unix Shell Script.

The script prompt the user to enter some input feilds and then based on user input it needs to look other values from properties file

Example
abc.properties file has following properties
Dev.DB2.name=someDEVDB2
Dev.DB2.ID=someDEVID
QA.DB2.name=someQADB2
QA.DB2.ID=someQAID

The script prompt use to enter the region as Dev or QA

Based on this the script need to get the value from property file.
The region is read as
$regionName say Dev

now i need to get the value of DB2.name
i tried doing
DB2_NAME= ${regionName}.DB2.name
but this doesnot return someDEVDB2

Any help is really appreciated
# 2  
Old 06-03-2011
Quote:
Originally Posted by WhtNxt01
i tried doing
DB2_NAME=${regionName}.DB2.name
but this doesnot return someDEVDB2
It doesn't substitute twice. If you want to get a name indirectly like that, try
Code:
DB2_NAME=${regionName}.DB2.name
echo ${!DB2_NAME}

# 3  
Old 06-03-2011
Quote:
Originally Posted by Corona688
It doesn't substitute twice. If you want to get a name indirectly like that, try
Code:
DB2_NAME=${regionName}.DB2.name
echo ${!DB2_NAME}

Corona688 - This too didnt work, when i excute the ksh script i get the error back as bad substitution
# 4  
Old 06-03-2011
If your shell doesn't support variable references you'll have to use the eval hack, then. That forces it to evaluate the text it's been given as a raw shell statement again.

Code:
$ VARA=A
$ VARB=B
$ VARAB=1234

$ VAR=`eval echo "\\$VAR$VARA$VARB"`
$ echo $VAR
1234
$


Previous Thread | Next Thread
Test Your Knowledge in Computers #215
Difficulty: Easy
Cisco IOS has a monolithic architecture.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to grab output in variable

bash-3.2$ time rm -rf /tmp/logs/server1.out I wish to check if is more than 10 secs then exit 5; else; exit 7 How can i capture the row value for real in the output shown above ? I am also not able to redirect the output to a file. Can you please suggest ? (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

Unable to set my PATH variable

Hello All, Hope you can understand my problem from the below code. $ cat ~/.profile PS1=`whoami`@`hostname`':$PWD $ ' export PATH="$PATH:.:/logarchive/utility/util:/usr/sbin:" $ echo $PATH /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:.:/usr/sbin: $ echo $SHELL /usr/bin/ksh ... (6 Replies)
Discussion started by: sathyaonnuix
6 Replies

3. Shell Programming and Scripting

Unable to read Environment Variable

Hi I have created the following shell script file with the following content. #!/bin/csh set VAR1="abcxyz" << EOF EOF echo "---------------------" echo "VAR1 = $VAR1" echo "---------------------" i am not able to echo the previously set VAR1. Can any one suggested what could be wrong?... (5 Replies)
Discussion started by: srinu_b
5 Replies

4. Shell Programming and Scripting

Unable to assign command output to variable

Code set -x STATUS="0" echo $STATUS for i in `ls -ltr Report*|awk '{ print $9 }'` do if then flg = "`head -1 "$i" |cut -c 31-33`" echo `head -1 "$i" |cut -c 31-33` echo $flg if then echo "having Fun" STATUS="2" else echo "no Fun" fi fi (2 Replies)
Discussion started by: Funkeydude
2 Replies

5. UNIX for Dummies Questions & Answers

awk unable to compare the shell variable

Hi Could anyone please help with Awk. The below code prints the PID of the matching process with condition with $8 and $9 ps -ef |awk '($8~/proc/) && ($9~/rPROC2/) {print $2}' Now i want to change the Constant PROC2 from Shell variable PROC2 is already declared in shell variable SRVNAME... (9 Replies)
Discussion started by: rakeshkumar
9 Replies

6. UNIX for Advanced & Expert Users

Unable to export delimiter as variable to SQL

Hi, I'm using a shell wrapper to trigger a teradata sql fastexport script as follows: #!/bin/ksh export delm=`echo "\t"` fexp <<! SELECT COALESCE(TRIM(CAST(col1 AS VARCHAR(10))),'') ||'$delm'|| COALESCE(CAST(col2 AS VARCHAR(10)),'') ||'$delm'|| COALESCE(TRIM(col3),'') FROM TABLE; ... (11 Replies)
Discussion started by: sumoka
11 Replies

7. Shell Programming and Scripting

Unable to add user defined variable

Hi, I have a user defined variable _TIME1=xxx I am using awk command for pattern matching. cat $_LOCATION/catalina.txt | awk '/^`$_TIME1`:??:??/' It not taking the value of $_TIME! eg:I am using the command to get all the patter from 12:00:00 to 12:59:59 The user defined variable... (2 Replies)
Discussion started by: ahamed
2 Replies

8. Shell Programming and Scripting

Unable to declare a variable in Cygwin

I recently installed Cygwin on my windows vista to practice on Linux\unix commands. I am unable to do a simple task of declaring variables on the command prompt I am trying: $ vech=Bus $ echo $vech bash: vech : command not found What am I missing? Do i need to add something to .bashrc? ... (1 Reply)
Discussion started by: erora
1 Replies

9. Shell Programming and Scripting

Unable to access variable outside loop

I am unable to access the value set inside the loop from outside loop . Thought of taking this to forum , I had seen other replies also , where a pipe takes the execution to another shell and mentioned thats the reason we do not get the variable outside loop . But I am getting an issue and I am... (1 Reply)
Discussion started by: Armaan_S
1 Replies

10. Shell Programming and Scripting

unable to access a variable not local to a while loop

I have a while loop like this cat ${filename} | while read fileline do ... done I need to access a variable value $newfile inside this while loop How will i do that?? (6 Replies)
Discussion started by: codeman007
6 Replies

Featured Tech Videos