Yes, sh -
and bash -
do mean the same.
In man bash, there is this description (emphasis mine):
--
A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments. An argument of - is equivalent to --
That simply means that it signals the end of options and that any following tokens are arguments (not options) even if they start with a dash -
.
And a POSIX sh has a similar description.
Thus, this volume of POSIX.1-2017 allows the single to mark the end of the options, in addition to the use of the regular "--" argument, because it was considered that the older practice was so pervasive.
This command:
$ echo "date" | sh -
Mon Feb 12 00:00:00 UTC 2018
But also does this:
$ echo "date" | sh
Mon Feb 12 00:00:00 UTC 2018
And this
$ echo "date" | sh -s
Mon Feb 12 00:00:00 UTC 2018
This will make clear what is being executed:
$ echo "date" | sh -x
+ date
Mon Feb 12 00:00:00 UTC 2018
But this will fail:
$ echo "date" | sh - -x
sh: 0: Can't open -x
That means that the date string is being read as a command from the standard input and that the dash (-) signals the end of options and start the arguments (the same as -- would do).
-
as a marker to read from stdin. As you can see from the (unfortunately downvoted) answer here the-
can mean different things to different shells. Forbash
it's a synonym for--
and not a stdin marker. For at least one other shell it appears to be undefined. – Chris Davies Feb 12 '18 at 17:08-
is a marker for stdin. I guess on this one we just disagree. – Chris Davies Feb 13 '18 at 09:24