Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does " - " mean stdout in bash?

Tags:

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!

like image 852
Tim Avatar asked Sep 26 '10 12:09

Tim


People also ask

What does stdout mean in bash?

Stdout in the command pipeline In bash, sequential commands can connect by pipes, represented on the command line by a vertical bar ("|"). Pipeline commands are processed left-to-right, with the standard output (stdout) of each command connecting to the standard input (stdin) of the next.

What is the meaning of 2 >& 1?

1 "Standard output" output file descriptor. The expression 2>&1 copies file descriptor 1 to location 2 , so any output written to 2 ("standard error") in the execution environment goes to the same file originally described by 1 ("standard output").

What does stdout mean?

Standard output (stdout) Standard output is a stream to which a program writes its output data. The program requests data transfer with the write operation. Not all programs generate output.

What is >& 2 in shell script?

and >&2 means send the output to STDERR, So it will print the message as an error on the console. You can understand more about shell redirecting from those references: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Redirections.


1 Answers

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).
like image 166
Matteo Italia Avatar answered Sep 27 '22 20:09

Matteo Italia