3

I see this symbol all the time and my book has yet to clarify what it means. None of the man pages or web searches clarify this either. At first I believed it to be a I/O symbol, but that never works when I try to play with it.

For example, in the patch Man and Info documents, it say

You can also specify where to read the patch from with the '-i PATCHFILE' or '--input=PATCHFILE' option. If you do not specify PATCHFILE, or if PATCHFILE is '-', 'path' reads the patch (that is, the 'diff' output) from the standard input.

When ever I see the '-' symbol, it is almost followed (at some point) by some mention of standard input.

What am I missing here? Does this symbol reference standard input? What does '-' mean in the context of Bash?

2 Answers2

4

Bash doesn't interpret a - argument at all. It is merely a convention implemented by many programs.

You usually see it when a program normally works on files, so they need some text string that isn't likely to be a file name to use when you want it to work on stdin/stdout instead.

It is highly unlikely that you will run into a system with a file purposely named -, because that's the standard option character on Unix. But, because it is in fact legal to name a file - — or more generally any file beginning with - — many programs that understand a - argument also understand the option --, meaning "stop processing options." This lets you do things like remove a file called -:

$ rm -- -
Warren Young
  • 72,032
1

To the best of my knowledge this is not a bash construct but a convention. Apps use - to denote reading from stdin or write to stdout in lieu of an actual file or writing /dev/stdin /dev/stdout.

Dani_l
  • 4,943