Terminal – What Options Does Terminal Pass to Bash on Startup?

bashcommand linemacosmacportsterminal

In the Terminal preferences, I'm able to configure the Terminal to "Open shells with:" -> "Command (complete path):" /opt/local/bin/bash.

What options is the terminal passing when invoking this command? Terminal appears to run each shell as a login shell, so I'm assuming --login is being passed?

Is there any Apple documentation that gives an overview of exactly what is being run when you open a terminal window?

Best Answer

No arguments are passed. The terminal runs login -pfq $USER $PROGRAM, which in turn runs the specified program. login signals to the program that it is a login shell by prepending a - to argv[0] (the program name).

For the default shell, Terminal actually does something different. It invokes login -pfl $USER /bin/bash -c exec -la bash /bin/bash, where the -l option to login tells it not to run the command as login shell, while the -l option to exec tells it to run its argument as a login shell (by adding the dash). The reason while this is done is that login also sets the current directory to the user's home directory when it runs a program as a login shell, while exec doesn't. This allows the Terminal to open shells in the same current directory as the current tab, without login setting it back to the home directory.