rm -- --somefile
While that works, it's a solution that relies on rm
using getopts for parsing its options. There are applications out there that do their own parsing and will puke on that too (because they might not necessarily implement the "--
means end of options" logic).
Because of that, the solution you should drive through your skull is this one:
rm ./--somefile
It will always work, because this way your arguments never begin with a -
.
Moreover, if you're trying to make really decent shell scripts; you should technically be putting ./
in front of all your filename parameter expansions to prevent your scripts from breaking due to funky filename input (or to prevent them being abused/exploited to do things they're not supposed to do: for instance, rm
will delete files but skip over directories; while rm -rf *
will delete everything. Passing a filename of "-rf
" to a script or somebody touch ~victim/-rf
'ing could in this way be used to change its behaviour with really bad consequences).