mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2177 (markdown)
20
SC2177.md
Normal file
20
SC2177.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
## 'time' is undefined for compound commands, time sh -c instead.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
time for i in *.bmp; do convert "$i" "$i.png"; done
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
time sh -c 'for i in *.bmp; do convert "$i" "$i.png"; done'
|
||||||
|
```
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
`time` is only defined for Simple Commands [by POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/time.html). Timing loops, command groups and similar is not.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None. If you use a shell that supports this (e.g. bash, ksh), specify this shell in the shebang.
|
Reference in New Issue
Block a user