3

This question already has an answer here:

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?

marked as duplicate by Michael Homer, Community Mar 25 '16 at 6:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It's a string that patch chose to give a meaning to (encouraged by POSIX); it has no innate meaning. I know there's a duplicate of this question around, but "-" is a nightmare to search for. I will try to find it. – Michael Homer Mar 25 '16 at 6:28
  • Also relevant: Is - used only with cd? – Michael Homer Mar 25 '16 at 6:32
  • you're right in the fact that it is a nightmare to search for. I figured someone at some point had to ask it, but nothing was showing up. – user147135 Mar 25 '16 at 6:36
3

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