Tim
Tim

Reputation: 99398

Does " - " mean stdout in bash?

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!

Upvotes: 18

Views: 4001

Answers (4)

Matteo Italia
Matteo Italia

Reputation: 126777

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

Upvotes: 29

sth
sth

Reputation: 229563

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

Upvotes: 5

Bruno
Bruno

Reputation: 122599

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

Upvotes: 10

Femaref
Femaref

Reputation: 61427

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"

Upvotes: 2

Related Questions