Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash command name starts with '-' (minus)

Tags:

shell

unix

login

If I run this command from my login shell:

$ echo $0

It returns:

-bash

Why does the login shell have a minus sign in the front? If I run bash again, then $0 is just "bash".

like image 583
sep332 Avatar asked Jun 23 '14 15:06

sep332


People also ask

What does $- mean in bash?

$- (dollar hyphen) bash parameter is used to get current option flags specified during the invocation, by the set built-in command or set by the bash shell itself.

What is $() called in bash?

It turns out, $() is called a command substitution.

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.

How do you check if a string starts with a letter in bash?

We can use the double equals ( == ) comparison operator in bash, to check if a string starts with another substring. In the above code, if a $name variable starts with ru then the output is “true” otherwise it returns “false”.


1 Answers

The name -bash means that bash was invoked as a login shell. The name bash means it was invoked as a non login shell. Check out Difference between Login Shell and Non-Login Shell? for more info.

like image 132
2 revs Avatar answered Nov 15 '22 08:11

2 revs