Is " - " a shortcut for stdout in bash? If not what does it mean? For example,
wget -q -O - $line
How about stdin?
Thanks and regards!
Is " - " a shortcut for stdout in bash? If not what does it mean? For example,
wget -q -O - $line
How about stdin?
Thanks and regards!
It depends on the program. Ususally, -
means "send to the output".
Use read
:
#!/bin/bash
echo -n "What's your name? "
read var1
echo "hello $var1"
-
is just a convention used by wget
(and quite a few other tools) to indicate the output is to be sent to stdout. It's not part of bash, but it's a special case treated by the command itself (some commands will end up creating a "-
" file if you assume this is the case). You could replace it with /dev/stdout
(and you can generally use /dev/stdin
as an input file when appropriate).
As far as I know, bash
isn't involved with the usage of dash. It's just a convention of many UNIX command line utilities to accept -
as a placeholder for stdin
or stdout
when put in place of an input or output file name on the command line.
For utilities that use operands to represent files to be opened for either reading or writing, the '-' operand should be used only to mean standard input (or standard output when it is clear from context that an output file is being specified).
-
is not special in bash, it is simply given as a parameter to the program. Then it depends on the program how it interprets that -
.
Commonly it denotes that stdin or stdout should be used, depending on context.