Why does `timeout` not work with pipes?

bash, pipe, timeout

Solution

What your command is doing is running `timeout 3 ls` and piping its output to `sleep 10`. The `sleep` command is therefore not under the control of `timeout` and will always sleep for 10s.

Something like this would give the desired effect.

timeout 3 bash -c "ls | sleep 10"

Problem

The following command line call of `timeout` (which makes no sense, just for testing reason) does not work as expected. It waits 10 seconds and does not stop the command from working after 3 seconds. Why ? ``` timeout 3 ls | sleep 10 ```

Original source