We have two scripts, first.sh
and second.sh
. We run first.sh
from second.sh
using the .
(source
) command.
I am stuck at this script,
first.sh
value="myvalue"
export value
oldvalue="othervalue"
export value
After initializing the value and exporting, we have initialized the oldvalue and again exported value
instead of oldvalue
, but still the othervalue
is available in the script second.sh
, even though we didn't export oldvalue
in first.sh
.
declare -p oldvalue
) from which it is run? – Hauke Laging May 30 '20 at 03:50declare -p oldvalue
in the shell from which the other script is run. In general: You can make environment variables available only to child processes. If you want some kind of independent inter-process communication you need a different mechanism e.g. a file which is written by one script and read by the other. – Hauke Laging May 30 '20 at 04:33.
orsource
, then that script is running in the same shell whereoldvalue
was set. Alternatively, it is possible thatoldvalue
was previously exported. Setting the value does not unexport it if done after the initial export. – camh May 30 '20 at 04:41.
, you're running the content of the second file in the same script, you're not running a separate script. – Andy Dalton May 30 '20 at 05:35declare: not found
, this is a shell question and a standard shell does not know aboutdeclare
. – schily May 30 '20 at 09:06