If you are executing your files like sh 1.sh
or ./1.sh
Then you are executing it in a sub-shell.
If you want the changes to be made in your current shell, you could do:
. 1.sh
# OR
source 1.sh
Please consider going through the reference-documentation.
"When a script is run using source
[or .
] it runs within the existing shell, any variables created or modified by the script will remain available after the script completes. In contrast if the script is run just as filename
, then a separate subshell (with a completely separate set of variables) would be spawned to run the script."
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…