Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass var name to sub-script and evaluate

Status
Not open for further replies.

mjpearson

Technical User
Dec 13, 2002
196
US
I'm taking my first Linux class so, I'm still learning.

I want to build a user-variable with value. I want to pass the variable-name to sub-script and have it print the value stored in the passed-variable name. I can't figure out the syntax. I've tried lots of different syntax and can't get it to work. Example below. Anyone got some advice?

script1
*******
var_name=%1
var_value=%2

$var_name=$var_value

./script2 $var_name

script2
*******
echo ${$%1}




mike
 
Another solution could be, to generate the script2 from script1:
Code:
#!/bin/bash
#
# Script1
#
VARNAME=$1
VARVALUE=$2

echo $VARNAME=$VARVALUE > script2
echo echo VARNAME=$VARNAME >> script2
echo echo VARVALUE=$VARVALUE >> script2
./script2

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top