shell - Can I export variable with another variable inside? -
i have .sh script uses environment variables export before. variables this: var1="${libdir}/test"
in script, ${libdir}
replaced value. declared export below: export var1="${libdir}/test"
in script libdir not taken account @ all. can way?
no, can't have variable contains variable reference gets substituted in "delayed" fashion:
$ libdir=foo $ var1="${libdir}/test" $ libdir=bar $ echo "$var1" foo/test
you could around using eval
, shouldn't.
however, function want, price of touch syntax:
$ var1() { echo "${libdir}/test" } $ libdir=foo $ echo "$(var1)" foo/test $ libdir=bar $ echo "$(var1)" bar/test
Comments
Post a Comment