Unable to export the variable through script file [duplicate]

Running your script like

. ./script

or

source script

would execute your script in the current shell context (without creating a subshell) and the environment variables set within the script would be available in your current shell.

From the manual:

. filename [arguments]

Read and execute commands from the filename argument in the current
shell context. If filename does not contain a slash, the PATH variable
is used to find filename. When Bash is not in POSIX mode, the current
directory is searched if filename is not found in $PATH. If any
arguments are supplied, they become the positional parameters when
filename is executed. Otherwise the positional parameters are
unchanged. The return status is the exit status of the last command
executed, or zero if no commands are executed. If filename is not
found, or cannot be read, the return status is non-zero. This builtin
is equivalent to source.

Leave a Comment