Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does '-' if standing for stdin have a specific name?

In several command line applications, if you pipe stdin into them, you need to provide a - character instead of an input file.

Sample:

$ foo | bar -

Now I wonder: Does this - character have an official special name when used in this context, e.g. dashed stdin operator or something like this? If so, which one?

The background of my question is that I want to write a function that detects this character and then treats stdin accordingly instead of parsing the arguments as an array, and I wondered what to call this function.

like image 892
Golo Roden Avatar asked Oct 31 '22 08:10

Golo Roden


1 Answers

The POSIX standard doesn't use any special name for this usage of - character. It says:

For utilities that use operands to represent files to be opened for either reading or writing, the '-' operand should be used to mean only standard input (or standard output when it is clear from context that an output file is being specified) or a file named -.

and then

Where a utility described in the Shell and Utilities volume of POSIX.1-2008 as conforming to these guidelines is required to accept, or not to accept, the operand '-' to mean standard input or output, this usage is explained in the OPERANDS section. Otherwise, if such a utility uses operands to represent files, it is implementation-defined whether the operand '-' stands for standard input (or standard output), or for a file named -.

Manual pages don't seem to use any special name either:

If no files are specified, or if the file "-" is given, grep searches standard input.

So it seems you have to invent your own name.

like image 188
n. 1.8e9-where's-my-share m. Avatar answered Nov 15 '22 07:11

n. 1.8e9-where's-my-share m.