Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When you enter an invalid command at a bash prompt you get the message

-bash: {command}: command not found

What does the - at the very beginning signify?

share|improve this question
    
How exactly are you running the command? I tried to replicate, but I'm not getting the same results - e.g.> jhgjbjbkjln: command not found - no -bash: in there. Are you using bash in Unix, Linux, OSX, ...? I ask because maybe this is something a specific implementation put before the error message by default, and it doesn't mean anything... maybe. –  jim Aug 8 at 5:44
    
@jim Try ssh computername and your not count command to replicate . –  Bernhard Aug 8 at 5:48

2 Answers 2

up vote 23 down vote accepted

It means that it is a login shell.

From man bash:

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

(In bash terminology, the "zeroth" argument is the command name which, in your case, was bash.) bash uses this as a signal to do login activities such as executing .bash_profile, etc.

One way that the dash may be added automatically is if the shell is started with exec. From the Bash manual:

exec [-cl] [-a name] [command [arguments]]

[...] If the -l option is supplied, the shell places a dash at the beginning of the zeroth argument passed to command.

Example

Compare these two attempts to run the command nonexistent. First without -l:

$ exec bash
$ nonexistent
bash: nonexistent: command not found

And, second, with:

$ exec -l bash
$ nonexistent
-bash: nonexistent: command not found
share|improve this answer
3  
I think the part of the documentation you're quoting doesn't match up with your explanation. The fact that exec -l prepends a dash is a possible way that may cause bash to be run as -bash, but that by itself doesn't say that it is a login shell, and there is a very good chance that the OP hasn't used exec -l at all. The part of the documentation that says -bash makes it a login shell is "INVOCATION A login shell is one whose first character of argument zero is a -, or one started with the --login option." –  hvd Aug 8 at 11:05
    
@hvd, agreed. Though correct, this answer misses the point. –  Stéphane Chazelas Aug 8 at 12:35
1  
"The zeroth argument" is not bash terminology, but Unix convention + C indexing: Each program gets passed a parameter list, whose initial entry is the program name, followed by the arguments. Since C arrays are indexed starting with zero, argument zero (that is, the zeroth argument) is the program name, and the actual arguments start with index 1. –  celtschk Aug 8 at 12:46

The other answer is fine as far as it goes, but it's worth mentioning that the feature is more general than bash.

Since ancient times, the login program has prepended a dash to argv[0] when it executes the user's shell, and the shell has recognized this as a sign that it should behave as a "login shell". It is documented in the V7 man pages here: login(1), sh(1).

All programs that provide a login-like service (authenticate a user and run a shell) should follow the "prepend dash" rule. For example, sshd does as you can see in ssh/session.c under this comment:

/*
 * If we have no command, execute the shell.  In this case, the shell
 * name to be passed in argv[0] is preceded by '-' to indicate that
 * this is a login shell.
 */

All shells recognize the leading dash. The equivalent -l option doesn't exist in the classic Bourne shell or original csh, but most newer shells (bash, dash, ksh, yash, tcsh, zsh, rc, es, fish and any semi-recent version of csh) have it.

share|improve this answer
    
Even though most shells now have the -l option, login still doesn't use it. All shells are expected to recognize the prefix on argv[0] as the "official" mechanism. –  Barmar Aug 13 at 20:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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