Hi ,
One of my file t1.sh has got some variables with values set.
When I run the second script I can not get the values of variables set in 1st script. Though I can only echo SYS Level set variables.
Any idea?
Many thanks
Printable View
Hi ,
One of my file t1.sh has got some variables with values set.
When I run the second script I can not get the values of variables set in 1st script. Though I can only echo SYS Level set variables.
Any idea?
Many thanks
Completely normal.
Variables are only valid within one process.
One method is to call the second script with parameters, and then parse the parameters into variables within the second script.
This is possible, but you must export the variables and execute t1.sh in the same process as your script:
Code:$> cat t1.sh
#!/bin/bash
export FOO="bar"
BAR="foo"
$> cat script.sh
#!/bin/bash
echo "var FOO equals: <$FOO>"
echo "var BAR equals: <$BAR>"
$> . ./t1.sh
$>
$> ./script.sh
var FOO equals: <bar>
var BAR equals:<>
$>. ./script.sh
var FOO equals: <bar>
var BAR equals: <foo>