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?


The 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).


  • Pay it forward 8-)
    – slm
    Sep 17 '13 at 18:02
  • Ah, so it sort of takes care of inconsistencies in bash profile file names?
    – Andrew
    Sep 17 '13 at 18:04
  • 1
    You're launching a new shell. So if you've made changes to a shell config, running the $SHELL -l command would "apply" those changes. Running source ~/.profile would do so similarly without starting a new shell, except any variables or functions in your config that are not overwritten will remain set as they were initially.
    – jktravis
    Sep 17 '13 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.