How to echo a value of a var stored in another variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to echo a value of a var stored in another variable?
# 1  
Old 05-17-2017
Question How to echo a value of a var stored in another variable?

I'm writing a shell script in AIX and using ksh.

I have a scenario where I have a variable A which stores $B.
so when i echo "$A" it prints $B

But I wish to print value stored in var b ie. \a\dir\res\

I wish to store \a\dir\res\ in a third variable C.
later I want to cd into that path : cd $C

How can I do it.

Last edited by simpltyansh; 05-17-2017 at 09:54 AM..
# 2  
Old 05-17-2017
Not sure I understand what you're after, and not sure either if that sort of redirection is the best way to do what you want.
You might want to try using eval to evaluate / expand variable twice, but this has its imponderabilia attached to it and may become dangerous, so be sure what exactly you're doing.
Another option is a sort of redirection that ksh offers, using ${!vname} expansion.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Resolve parameter value stored in a variable

Hi All, I have below variable, xyz=\$AI_XFR Now, if you will run the below command => echo $xyz $AI_XFR It is returning hardcoded string value. Whereas in environment, there is value in it. Like below: => echo $AI_XFR /home/aditya/sandbox/xfr/ I need to resolve this... (4 Replies)
Discussion started by: adgangwar
4 Replies

2. Red Hat

How to check values stored in variable?

hey, i have stored values of query like this val_2=$( sqlplus -s rte/rted1@rel75d1 << EOF set heading off select source_id from cvt_istats where istat_id > $val_1; exit EOF ) echo $val_2 now , val_2 has five values displayed like this 1 2 3 4 5 what i have to do is to check the... (1 Reply)
Discussion started by: ramsavi
1 Replies

3. Shell Programming and Scripting

Variable not found error for a variable which is returned from stored procedure

can anyone please help me with this: i have written a shell script and a stored procedure which has one OUT parameter. now i want to use that out parameter as an input to the unix script but i am getting an error as variable not found. below are the unix scripts and stored procedure... ... (4 Replies)
Discussion started by: swap21783
4 Replies

4. Shell Programming and Scripting

Home of user that is stored in var

I have a user name that is stored in variable $i and i want to use that user's home dirctor in case command something like this find ~"$i" |while read p do case "$p" in ( ~"$i"/myDir ) echo "$p" ;; (*) esac done but it doesn't work some help please (7 Replies)
Discussion started by: testman84
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

Problem regarding Sed/Echo/Var Init

Greetings, I've visited this forums for a long time and normally got an right answer but this time my problem doesn't seem to go away. What I'm trying to do is the following: VAR="\n\nline1\nline2\nline3\nline4\nline5\nline6\nline7\n\n" (The count of newlines is varying!) If I echo this i... (3 Replies)
Discussion started by: ph1l
3 Replies

7. Linux

Incrementing the date stored in the variable

Hi all, I have a variable with date as 20080831 . Now I want to increment it as 20080901 and so on.Is there any command for this. Please help me. thanks rameez (1 Reply)
Discussion started by: rameezrajas
1 Replies

8. Shell Programming and Scripting

how to get the string stored in a variable in a line???

Hi all, I want to search for a data type in a line.For this in a loop i am checking for $DATA_TYPE in a line using grep.But grep is not able to find when i give this. Can any one tell me how to check string in $DATA_TYPE variable in line usign grep (or) any other way to do the above task. ... (4 Replies)
Discussion started by: jisha
4 Replies

9. UNIX for Dummies Questions & Answers

can i exectue a command stored in a variable.it goes like this

hi the code i ve written is as follows: command="egrep ',100,|,200,' | wc -l" count =`cat trial.txt | $command` echo "$count" the contents of trial.txt is : 000,100,200,300, 001,200,100,201, 002,200,100,400, i need to get the count using the command stored in a variable and using... (2 Replies)
Discussion started by: Syms
2 Replies

10. Shell Programming and Scripting

Problem with echo for var, padded with spaces

While concatenating 2 values, one which expanded to fixed width & other not, I am not getting value expanded as fixed width. Following is script for the same : #!/bin/sh var1="abc" var2="def" var1Fxd=`echo $var1 | awk '{printf("%-6s",$0)}'` echo $var1Fxd""$var2 But, if I try - echo... (2 Replies)
Discussion started by: videsh77
2 Replies
Login or Register to Ask a Question