export
exports the variable assignment to child processes of the shell in which the export
command was ran. Your command-line environment is the parent of the script's shell, so it does not see the variable assignment.
You can use the .
(or source
) bash command to execute the script commands in the current shell environment and achieve what you want, e.g.
source ./script.sh
echo "$BASE"
Will produce
/home/develop/trees
The source
command, often seen in scripts, is a bash synonym for .
, which is part of the POSIX standard (so .
is available in dash, for example, but source
isn't).
. ./script.sh # identical to "source ./script.sh"
(. script.sh
and source script.sh
will first look for script.sh
in PATH
, so it's safer to specify the path to script.sh
.)