In bash, if I run
(foo=14)
And then try to reference that variable later on in my bash script:
echo \"${foo}\"
<
Commands enclosed in parenthesis e.g. ()
are executed in a sub-shell. Any assignment in a sub-shell will not exist outside that sub-shell.
foo=14
bar=$(echo $foo | tr '1' 'a' )
if [[ $? -eq 0 ]]
then
echo "Setting "'$bar'" was a success. It is ${bar}"
else
echo "Setting "'$bar'" failed with a nonzero exit code."
fi