mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created Sc2035 (markdown)
15
Sc2035.md
Normal file
15
Sc2035.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Use ./*.m3u so names with dashes won't become options.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
rm *
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
rm ./*
|
||||||
|
|
||||||
|
### Rationale
|
||||||
|
|
||||||
|
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.
|
Reference in New Issue
Block a user