Traço (-) na frente do bash

8

Se eu examinar meu bash shell em um terminal OS X (10.6.4), por exemplo, digitando echo $0 , há um traço na frente do meu shell, como este: -bash . O que esse traço significa?

    
por marshall.ward 04.05.2011 / 07:28

1 resposta

9

Isso significa que bash é invocado como um shell de login.

man bash diz:

A login shell is one whose first character of argument zero is a -, or one started with the --login option.

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

Você encontrará login -pf em sua ps output, que inicia um shell de login por padrão.

Tente executar login -pf e login -pfl e veja a diferença. man login descreve a diferença:

-l Tells the program executed by login that this is not a login session (by convention, a login session is signalled to the program with a hyphen as the first character of argv[0]; this option disables that), and prevents it from chdir(2)ing to the user's home directory. The default is to add the hyphen (this is a login session).

    
por 04.05.2011 / 08:04

Tags