Working filenames in shell begins with a dash character

If you accidently create a file which names begins with a dash (-) character, you'll be realize that you can't simply delete this file with regular rm command:

rm -f -testfile
rm: invalid option -- t

Because of the first character is a dash, shell thinks we want to provide an option to rm commands itself. Solution of this problem is to use double dash character -- after our command's options are finished:

rm -f -- -testfile

it works. When -- character seen, shell thinks that optional arguments for command itself finished and doesn't make option parsing anymore.

 







You must be login first or sign-up for an account to post comments.

Maybe you should look at these also: