SC2176 – ShellCheck Wiki

See this page on GitHub

Sitemap


time is undefined for pipelines. time single stage or bash -c instead.

Problematic code:

time foo | bar

Correct code:

To time the most relevant stage:

foo | { time bar; }

To time everything in a pipeline:

time bash -c 'foo | bar'

Note that you can not use time sh -c to time an entire pipeline, because POSIX does not guarantee that anything other than the last stage is waited upon by the shell.

Rationale:

This behavior is explicitly left undefined in POSIX.

Exceptions:

None. This warning is not emitted in ksh or bash where time is defined for pipelines.


ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.