rm ./-filename
works for me.NOTES
The rm command uses getopt(3) to parse its arguments, which allows it to
accept the `--' option which will cause it to stop processing flag
options at that point. This will allow the removal of file names that
begin with a dash (`-'). For example:
rm -- -filename
The same behavior can be obtained by using an absolute or relative path
reference. For example:
rm /home/user/-filename
rm ./-filename
--
, so everything after that is treated as "positional argument", even if it starts with a dash.What do you mean with "got by glob"? It's on the commandline andBuit still I wonder, why names got by glob are still seen as options. That may be risky.
-
is the special character for an option. It was always that way on any Unix-like system.The file was named -tmp-3. AlsoWhat do you mean with "got by glob"?
ls *tmp-3
does not work.So, you know theThe file was named -tmp-3. Alsols *tmp-3
does not work.
*
is expanded by your shell and not by ls
?So, you know the*
is expanded by your shell and not byls
?
It's not a bug, it's expected behavior.It is a bug in my oppinion.
It is specified in POSIX that globs are expanded by the shell (and if you want to pass them unexpanded to a command, you have to escape them). Your "opinion" doesn't count here.es, but tcsh and sh are doing that. It is a bug in my oppinion.
How?you have to escape them
\
. To get a literal question mark for example: touch \?
. Or use single quotes, touch '?'
. Single and double quotes are treated differently too. There's a difference between touch "$foo"
and touch '$foo'
.All that does not work in the case treated here. Perhaps it is you who have to learn something?Methods for escape something in a shell are putting it in double-quotes, single-quotes, or (for single characters) put a backslash in front of it.
Yes, but by quoting the commands will still consider the argument as option.You escape characters using t
ls
nor rm
understand globs!I am not as perfect as you are. Thats all.but obviously have no clue how things work.
Your strong opinions are always based on right understanding, because you always understand things rightbut basing strong opinions ("bug", "you have to learn something", etc…) on a wrong understanding is.
From all your interventions, this is the only what I appreciate and thank. Also for reminding me that theThe behavior of FreeBSD is POSIX compliant, and of course you will find the same behavior in any other Unix-like system (if it isn't broken).
Specifically, the double-dash is documented here (guideline 10):
Utility Conventions
But for not doing that, you must know that you misunderstood something, and hence it would notDon't claim something is a bug just because you misunderstood something.
No:Note that by recommending quoting you fell in the very same lapsus.
Methods for escape [..]
Be aware neitherls
norrm
understand globs.