What exactly are the uses of '-' in bash? I know they can be used for
cd -
# to take you to the old 'present working directory'some stream generating command | vim -
# somehow vim gets the text.My question is what exactly is - in bash? In what other contexts can I use it?
Regards Arun
$- (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. The command in between $() or backticks (“) is run and the output replaces $() . It can also be described as executing a command inside of another command.
Set –e is used within the Bash to stop execution instantly as a query exits while having a non-zero status. This function is also used when you need to know the error location in the running code.
The [[ ... ]] part allows to test a condition using operators. Think of it as an if statement. In your example, you're using the -s operator, which tests that the referenced file is not empty. Copy link CC BY-SA 3.0.
That depends on the application.
cd -
returns to the last directory you were in.
Often -
stands for stdin
or stdout
. For example:
xmllint -
does not check an XML file but checks the XML on stdin
. Sample:
xmllint - <<EOF
<root/>
EOF
The same is true for cat
:
cat -
reads from stdin
. A last sample where -
stands for stdout
:
wget -O- http://google.com
will receive google.com by HTTP and send it on stdout
.
By the way: That has nothing to do with your shell (e.g. bash
). It's only semantics of the called application.
-
in bash has no meaning as a standalone argument (I would not go as far as to say it it does not have a meaning in shell at all - it's for example used in expansion, e.g. ls [0-9]*
lists all files starting with a digit).
As far as being a standalone parameter value, bash will do absolutely nothing special with it and pass to a command as-is.
What the command does with it is up to each individual program - can be pretty much anything.
There's a commonly used convention that -
argument indicates to a program that the input needs to be read from STDIN instead of a file. Again, this is merely how many programs are coded and technically has nothing to do with bash.
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