What does this command do? “exec bash -l”

前端 未结 2 1825
情歌与酒
情歌与酒 2021-01-04 23:39

What does this command do?

exec bash -l

I found this command as part of a reminder text file were I wrote some instructions regarding how t

相关标签:
2条回答
  • 2021-01-05 00:40

    This will replace your current shell with a new bash shell run as a login shell.

    0 讨论(0)
  • 2021-01-05 00:42

    exec executes a specified command, replacing the current process rather than starting a new subprocess.

    If you type

    bash -l
    

    at a shell prompt, it will invoke a new shell process (the -l makes it a login shell). If you exit that shell process, you'll be back to your original shell process.

    Typing

    exec bash -l
    

    means that the new shell process replaces your current shell process. It's probably slightly less resource intensive.

    The reason for doing it is probably so that the new shell sets up its environment (by reading your .bashrc, .bash_profile, etc.).

    See the bash documentation for more information:

    • Bash Startup Files for how a login shell differs from a non-login shell
    • Bourne Shell Builtins for documentation on the exec command.

    (You should be able to read the manual on your own system by typing info bash.)

    0 讨论(0)
提交回复
热议问题