18

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!

0

4 Answers 4

29

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

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

0
5

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

2

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.