in reply to Using -- to terminate switch processing

I'd have to ask you collegue: Why? What (potential) errors does the addition of the '--' prevent?

Whilst the system I use does not depend upon the shebang line to find the executable, it does respect most switches applied via a shebang line. Adding additional, non-switch tokens after the switches, with or without the presence of '--' has no discernable effect upon the function of the script. Therefore I see no reason to add the '--'.

I'd be interested to know if there are any effects or caveats that I haven't yet discerned.


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.
  • Comment on Re: Using -- to terminate switch processing

Replies are listed 'Best First'.
Re: Re: Using -- to terminate switch processing
by Kanji (Parson) on Mar 26, 2003 at 18:28 UTC
    What (potential) errors does the addition of the '--' prevent?

    On systems that do depend on the shebang to find the executable, a stray carriage return (as so often happens when transferring files from Windows to Unix) can break that magic. Adding -- in such cases ensures that the trailing ^M never interferes with the binary name. Then again, adding ANY switch seems to accomplishes the same...

    $ cat -e cM.pl #!/usr/bin/perl^M$ ^M$ print "Hello, World!";^M$ $ ./cM.pl : bad interpreter: No such file or directory $ cat -e cM--.pl #!/usr/bin/perl --^M$ ^M$ print "Hello, World!";^M$ $ ./cM--.pl Hello, World!

        --k.


      I hit this when using -F/pattern/ as the last argument on a shebang line moved to windows. So maybe it makes the script more portable. I'd prefer it if perl could take care of it though.