diff --git a/SC2177.md b/SC2177.md new file mode 100644 index 0000000..9070f2f --- /dev/null +++ b/SC2177.md @@ -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. \ No newline at end of file