mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated Sc2035 (markdown)
10
Sc2035.md
10
Sc2035.md
@@ -1,11 +1,15 @@
|
|||||||
# Use ./*.foo so names with dashes won't become options.
|
# Use ./\*glob* or -- \*glob* so names with dashes won't become options.
|
||||||
|
|
||||||
### Problematic code:
|
### Problematic code:
|
||||||
rm *
|
rm *
|
||||||
|
|
||||||
### Correct code:
|
### Correct code:
|
||||||
|
|
||||||
rm ./*
|
rm ./*
|
||||||
rm -- * # This is sane, too, as -- is a popular end-of-options seperator
|
|
||||||
|
or
|
||||||
|
|
||||||
|
rm -- *
|
||||||
|
|
||||||
### Rationale
|
### Rationale
|
||||||
|
|
||||||
@@ -15,4 +19,6 @@ A file named `-f` (`touch -- -f`) will not be deleted by the problematic code. I
|
|||||||
|
|
||||||
Using `./*` will instead cause the glob to be expanded into `./-f`, which no program will treat as an option.
|
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](http://www.dwheeler.com/essays/filenames-in-shell.html)".
|
For more information, see "[Filenames and Pathnames in Shell: How to do it Correctly](http://www.dwheeler.com/essays/filenames-in-shell.html)".
|
||||||
|
Reference in New Issue
Block a user