All ---aware programs I’ve encountered understand it the same way: it marks the end of named parameters; all arguments following it are bound to positional ones. To illustrate, these three invocations are equivalent:
cp -f -- a b
cp -f a -- b
cp -f a b
This is necessary in order to support binding an argument that starts with a dash to a positional one:
cp -- a -R # Copy the file named `a` to a file named `-R`.
cp a -- -R # Ditto.
This is important to a program user if the names aren’t known in advance:
cp -- "$from" "$to" # Will work predictably no matter what these variables contain.
If we were implementing cp in D, we’d like to declare it as follows:
A program should never need to know if it was invoked with -- or without. If it needs to accept a variable number of arguments, it just asks for @(PositionalArgument(0).Optional) string[ ] rest.
All
--
-aware programs I’ve encountered understand it the same way: it marks the end of named parameters; all arguments following it are bound to positional ones. To illustrate, these three invocations are equivalent:This is necessary in order to support binding an argument that starts with a dash to a positional one:
This is important to a program user if the names aren’t known in advance:
If we were implementing
cp
in D, we’d like to declare it as follows:…and expect everything to work out of the box.
A program should never need to know if it was invoked with
--
or without. If it needs to accept a variable number of arguments, it just asks for@(PositionalArgument(0).Optional) string[ ] rest
.