mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2202 (markdown)
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
[ current.log -nt backup/*.log ] && echo "This is the latest file"
|
[ current.log -nt backup/*.log ] && echo "This is the latest file"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Correct code:
|
### Correct code:
|
||||||
@@ -30,7 +29,7 @@ Instead, use a `for` loop to iterate over matching filenames, and apply your con
|
|||||||
|
|
||||||
If you know your glob will only ever match one file, you can check this explicitly and use the first file:
|
If you know your glob will only ever match one file, you can check this explicitly and use the first file:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
set -- backup/*.log
|
set -- backup/*.log
|
||||||
[ $# -eq 1 ] || { echo "There are too many matches."; exit 1; }
|
[ $# -eq 1 ] || { echo "There are too many matches."; exit 1; }
|
||||||
[ file.log -nt "$1" ] && echo "This is the latest file"
|
[ file.log -nt "$1" ] && echo "This is the latest file"
|
||||||
|
Reference in New Issue
Block a user