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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable value not retained

Status
Not open for further replies.

gotchausa

Programmer
Jan 24, 2002
64
0
0
CA
I've got a .sh script that uses various functions within it. It looks something like this:

x="text.sh $a"

function run
(
a=1
exec $x
)

run

When I run the script, the script complains that $a is empty. Why does the value of '1' not get passed when $x is executed???
 
you have to force to re-evaluate the '$x':
eval "${x}"

before exec-ing. Your 'x' is evaluated at teh time of the declaration with whatever '$a' was at the time [if any].

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
#!/bin/ksh
#set -x

x='text.sh ${a}'

function run
{
a=1
eval &quot;${x}&quot;
}

run


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top