Note: my answer is NOT valid in the OP's case, and only applies to tools following the convention mentioned below and not in the case of a file named exactly just -
(dash), which is often also a special case to specify that reading from standard input is expected. See the accepted answer.
Leaving this here as it contains useful information for other cases that one may stumble upon while searching for answers.
Double-Dash it!
Use the standard double-dash (--
) convention to indicate the last argument:
less -- -FILENAME
Example
$ echo "meh" > -badname
$ less -badname
Number is required after -b
$ less -- -badname # GREAT SUCCESS!
Whhhaattt?
This --
argument stems from a convention supported by most implementations of shell utilities and command-line tools, and most shells will visibly advocate that you should follow it when implemeing CLI tools.
Recommdended by the Open Group
The OpenGroup also mentions it in the Utility description defaults (v6) section of its Base Specification:
Default Behavior: [...] Standard utilities that do not accept options, but that do accept operands, shall recognize "--" as a first argument to be discarded.
The requirement for recognizing "--" is because conforming applications need a way to shield their operands from any arbitrary options that the implementation may provide as an extension. For example, if the standard utility foo is listed as taking no options, and the application needed to give it a pathname with a leading hyphen, it could safely do it as:
foo -- -myfile
and avoid any problems with -m used as an extension.
And in the Utility Syntax Guidelines (v7):
Guideline 10:
The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.
Recommended by Bash
Here, excerpted from the bash manual, about its builtins supporting it:
Unless otherwise noted, each builtin command documented in this section as accepting options preceded by - accepts -- to signify the end of the options.
The :, true, false, and test builtins do not accept options and do not treat -- specially. The exit, logout, break, continue, let, and shift builtins accept and process arguments beginning with - without requiring --. Other builtins that accept arguments but are not specified as accepting options interpret arguments beginning with - as invalid options and require -- to prevent this interpretation.
Note that echo does not interpret -- to mean the end of options.
Additional Reading
-
alone is different.-
is not an option. – Stéphane Chazelas Jun 17 '15 at 10:35-
is taken as an option. Yes,less
takes the-
alone as an option but most programs would choke on it for the same reason. Your basic question is "How can I use program foo on file-*
". The dupe is about the same thing as far as I can tell. Just as explained there, you can use./-
,-- -
,find
, or the full path. We've been closing questions asking about file names starting with-
against that one for a while, look at its linked questions. Wouldn't it have answered your question if you'd read it before posting? – terdon Jun 17 '15 at 11:29-
is not treated as an option, that's a totally different problem from the case of arguments that happen to be shaped like options. – Stéphane Chazelas Jun 17 '15 at 11:34-
between single quotes like'-'
or escape it like\-
because-
is not a special character for common shells (at least POSIX compliant ones). The result is the same. – pabouk - Ukraine stay strong Jun 17 '15 at 12:06mv -- - sensible_file_name
– user1024 Jun 17 '15 at 22:31