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