-5

I notice in https://unix.stackexchange.com/a/459007/674, that single dash - is used to signal the end of option arguments.

Is it correct that double dashes -- can also signal the end of option arguments?

What are their differences then? When to use which? Are they both GNU conventions? Thanks.

Tim
  • 101,790
  • If you'd asked what - means in a #! line you'd have had a question that we don't appear to have, but this we have questions about over and over, for over 7 years now. https://unix.stackexchange.com/q/253446/ https://unix.stackexchange.com/q/52167/ https://unix.stackexchange.com/q/11376/ https://unix.stackexchange.com/q/410689/ https://unix.stackexchange.com/q/375987/ https://unix.stackexchange.com/q/24275/ https://unix.stackexchange.com/q/55969/ https://unix.stackexchange.com/q/52425/ https://unix.stackexchange.com/q/457398/ https://unix.stackexchange.com/q/21852/ – JdeBP Jul 29 '18 at 18:07
  • 2
  • Interesting. I used "bash" as the search term. That does not come up in the results list. – JdeBP Jul 29 '18 at 19:39

2 Answers2

2

The single dash is per definition a file type argument and after a file type argument, a POSIX compliant application is not allowed to check for options.

The double dash is the POSIX definition for the end of the options. After that, only file type arguments are allowed.

So the convention for both differs, even though it may end up in a similar result.

This is not a GNU convention, but POSIX.

Also note that the convention to write:

#!/bin/sh -

or

#!/bin/sh -p

is from a time when neither the -- special argument nor the getopt(3) function were known.

schily
  • 19,173
1

Bash, specifically, accepts - as a synonym for --. In the examples given in the answer quoted in the question,

#! /bin/bash -

this is used to tell Bash that no more options follow, so that the shebang works irrespective of the name of the script -- consider for example what would happen if the script were named -l.

AlexP
  • 10,455