tags:

views:

75

answers:

4

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!

+1  A: 

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"
Femaref
+6  A: 

- 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).

Bruno
As others have said, "`-`" is also sometimes used to mean `/dev/stdin` when the parameter expects an input instead.
Bruno
+6  A: 

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.


Edit: found it, this behavior is specified in the POSIX Utility Syntax Guidelines, §12.2.13 of The Open Group Base Specifications:

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).
Matteo Italia
+2  A: 

- 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.

sth