-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2035
Devyn Collier Johnson edited this page Dec 7, 2015
·
7 revisions
rm *
rm ./*
or
rm -- *
Since files and arguments are strings passed the same way, programs can't properly determine which is which, and rely on dashes to determine what's what.
A file named -f
(touch -- -f
) will not be deleted by the problematic code. It will instead be interpreted as a command line option, and rm
will even report success.
Using ./*
will instead cause the glob to be expanded into ./-f
, which no program will treat as an option.
Similarly, --
by convention indicates the end of options, and nothing after it will be treated like flags.
For more information, see "Filenames and Pathnames in Shell: How to do it Correctly".