mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2176 (markdown)
30
SC2176.md
Normal file
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.
|
Reference in New Issue
Block a user