I have seen this command in a few different shell scripts:
exec $SHELL -l
...usually as an alternative to:
source ~/.profile
What exactly is exec $SHELL -l
doing?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThe exec command replaces the current process image - the executable or program - with a new one, named as the argument to exec. If $SHELL contains the name of an executable, as it usually does, exec will spin that exe up in place of the running shell.
HOWEVER, that's a very different action than just using "source" to read in a file of commands. The source command read the named file and executes the contents line by line, as though typed at the command line of the current shell.
It's invoking your shell ($SHELL
) as a login shell.
excerpt from Bash man page
-l Make bash act as if it had been invoked as a login shell
(see INVOCATION below).
I suggest reading through the INVOCATION section of the man page for more information.
Bottom line is that it tells Bash which files to source when it invokes. Either the $HOME/.bash_profile
(-l
) or the $HOME/.bashrc
(-i
).