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".
$- (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.
It turns out, $() is called a command substitution.
$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.
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”.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With