Could you please clarify on the use of
exec ls | cat
exec -l ls | cat
-l option of
exec adds a
- at the beginning of the name of your command. For example:
exec -l diff | head -diff: missing operand after '-diff' -diff: Try '-diff --help' for more information.
- everywhere before
The point of all this? If you have a
- before a command to start a shell it will act as a login shell. From
A login shell is one whose first character of argument zero is a -, or one started with the --login option.
man exec states that:
If the -l option is supplied, the shell places a dash at the beginning of the zeroth argument passed to command. This is what login(1) does.
exec -l bash will run
bash as a login shell. To test this, we can use the fact that a login bash reads your
$ cat ~/.bash_profile #!/bin/sh echo yoho
If I start a login bash, the command
echo yoho will be executed. Now to test with
$ exec bash $
Nothing is displayed, we are on a non-login shell.
$ exec -l bash yoho $
Here we have a login shell.