You probably don't want to do exit 1
; that is used to indicate failure. You'd use exit 0
to indicate success — but, as described below, you don't want to do that, either, in this case.
The other problem is that if you run the script as child process, it cannot affect the environment of the parent process.
To work around that, in POSIX shells, you need to use:
. your_script.sh
or, in bash
, you can also use:
source your_script.sh
The script does not have to be executable, just readable, and will be searched for on $PATH
unless you specify a name containing a slash, just like other commands.
And, when you do the .
or source
, you definitely do not want any exit
in the script because that will cause the main shell to exit. The shell reads the file as if you were typing it at standard input (more or less), so an exit
that's executed will exit the shell.
source ‘filename’
. – Gandaro Mar 12 at 18:22