cat is coded to compare the given filename against the string "-" before trying to open it as a file:
if (STREQ (infile, "-"))
have_read_stdin = true;
input_desc = STDIN_FILENO;
if (file_open_mode & O_BINARY)
xset_binary_mode (STDIN_FILENO, O_BINARY);
input_desc = open (infile, file_open_mode);
if (input_desc < 0)
error (0, errno, "%s", quotef (infile));
ok = false;
So, if you have a file named
-, you need to defeat this logic by giving
cat the path and name.
Quotation marks protect a value from white space splitting and, if single quotes, variable expansion. Quotation marks do not signal that the thing quoted is a file. To explicitly signal a value is a file, prefix it with a relative or absolute path.
All that said, one might suggest that GNU
cat should also check if
- is a file in the current working directory, but it'd be unusual for filenames to start with a hyphen or to be solely a hyphen, so that may be a performance concern. David Wheeler's essay, Fixing UNIX and Linux Filenames, has a nice discussion of this problem in historical context.