K Shell evaluating value to a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting K Shell evaluating value to a variable
# 1  
Old 11-12-2008
K Shell evaluating value to a variable

Hi,
I have the following requirement.

V="First"
R="V"

echo $$R

The output should be First. How do i achieve this.

how do we evaluate the $R and evaluate it to $V as $R contains V
and $V is First.

Thanks
Vijay
# 2  
Old 11-12-2008
try $R=${V}
or $R=$V
# 3  
Old 11-12-2008
Code:
$ V="First"
$ R="V"
$ eval echo \$$R
First

If your version of ksh supports nameref
Code:
$ V="First"
$ nameref R="V"
$ echo $R
First

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Korn shell - evaluating string gives wrong results due to limitations

Anyone ever seen this? Someone mentioned this the other day.... If you do, for instance, in korn shell, echo $(5.2+2.5), it gives the result of 6 regardless. Can't remember why but it was the limitation of the korn shell. (5 Replies)
Discussion started by: psychocandy
5 Replies

2. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

3. Shell Programming and Scripting

evaluating a variable inside a variable

Hi there, i think im getting myself a little confused and need some help :wall: I am reading in a bunch of variables to my script from an external file and need to validate that a value has been set for each so if you can imagine, the user is required to pass in 4 values... (3 Replies)
Discussion started by: rethink
3 Replies

4. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

5. Shell Programming and Scripting

Evaluating a variable

Does anyone know of a way to force a variable name held in another variable to return the value of the first variable? Best if I give an example, that does not work: /usr/local/bin >cat mike.sh NUM1ref=16 NUM2ref=32 echo "==============" for VAR in NUM1 NUM2 do XXXX=${VAR}ref echo $XXXX... (4 Replies)
Discussion started by: mikejordan
4 Replies

6. Shell Programming and Scripting

$$# is evaluating to 1 when no value

I have the following in my makefile: RESULT=`../${TOOLS_ROOT_PATH}/ext_tools.sh 11`; \ set $$RESULT > tMp; \ rm tMp; \ if ; then \ echo copying external-local tool: $< \($$*\); \ mkdir -p ${EXTERNAL_LOCAL_BIN_DIR}/$<; \ cp -f... (4 Replies)
Discussion started by: jake_ryan
4 Replies

7. Shell Programming and Scripting

Evaluating command output (shell script )

Hello, in a script i would like to evaluate a command output with a grep, for example, to know if the parameter defined by the user is in the output. Something like: the_command | grep $1 Please, how is the way to evalulate in this a script, like if echo "incorrect parameter, not in... (2 Replies)
Discussion started by: aristegui
2 Replies

8. Shell Programming and Scripting

Bash: evaluating $? variable (if statement)

Hello, i'm unable to write a correct if... statement to evaluate the $? variable. Could anybody send to me an example? for example, this lines of code didn't work... if ; then etc etc if ; then etc etc Thank you in advanced. (5 Replies)
Discussion started by: aristegui
5 Replies

9. Shell Programming and Scripting

* character evaluating too soon - Help!

I have a user defined configuration file, which could contain the following type of entries: directory_001=/a/directory/structure pattern_001=fred* pattern_002=* I have a script which reads the file generically which will loop round loop 1 genvar=”directory” iteration=”001” ... (11 Replies)
Discussion started by: Bab00shka
11 Replies

10. UNIX for Dummies Questions & Answers

evaluating params

Hi all, I ve a script like.... TBL=employee sql=`cat abhi.sql` \\ abhi.sql contains ------- select a from $TBL echo $TBL echo $sql SQL=`echo $sql` echo $SQL now i want SQL as select a from employee and as select a from $TBL How can I achieve this? Help appriciated (3 Replies)
Discussion started by: abzi
3 Replies
Login or Register to Ask a Question