1
0
mirror of https://github.com/koalaman/shellcheck.git synced 2025-03-12 12:35:25 -07:00

Created SC2176 (markdown)

koalaman 2016-03-19 16:53:10 -07:00
parent d178d300f5
commit 3a0383210c

30
SC2176.md Normal file

@ -0,0 +1,30 @@
## 'time' is undefined for pipelines. time single stage or bash -c instead.
### Problematic code:
```sh
time foo | bar```
### Correct code:
To time the most relevant stage:
```sh
foo | { time bar; }
```
To time everything in a pipeline:
```sh
time bash -c 'foo | bar'
```
Note that you can not `time sh -c` to time an entire pipeline, because POSIX does not guarantee that anything other than the last stage is waited on and therefore be recursively counted in the `times()` call that `time` depends on.
### Rationale:
This behavior is explicitly left undefined [in POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/time.html).
### Exceptions:
None. This method is not given in `ksh` or `bash` where `time` is defined for pipelines.