"-" means stdout in bash?

Is a "-" shortcut for stdout in bash? If not, what does this mean? For example,

wget -q -O - $line 

What about stdin?

Thank you and welcome!

+6
bash
source share
4 answers

As far as I know, bash not related to using dashes. This is simply the convention of many UNIX command-line utilities to accept - as a placeholder for stdin or stdout , if instead of the name of the input or output of the file on the command line.


Edit : found that this behavior is specified in the POSIX Utility Syntax Guide, §12.2.13 Open Group Base Group Specifications:
For utilities that use operands to represent files that need to be opened for reading or writing, the operand '-' should only be used to indicate standard input (or standard output when it is clear from the context that the output file is specified).
+13
source share

- - This is just the convention used by wget (and many other tools) to indicate that the output should be sent to stdout. It is not part of bash, but it is a special case that is handled by the command itself (some commands will create a file - if you assume it is). You can replace it with /dev/stdout (and usually you can use /dev/stdin as the input file).

+8
source share

- not special in bash, it is simply specified as a parameter for the program. Then it depends on the program, how it interprets it - .

This usually means that stdin or stdout should be used depending on the context.

+2
source share

It depends on the program. Usochno - means "send to the exit."

Use read :

 #!/bin/bash echo -n "What your name? " read var1 echo "hello $var1" 
+1
source share

All Articles