Double redirect test

What will it print your shell?

echo foo | while read line; do echo $line; done < <(echo bar)

I expect it to be rated as echo foo | baror foo < <(bar), both of which will result in an error message.

In Bash 4.1.5, it looks like the pipe is simply dropped:

bar

In the dash:

sh: Syntax error: redirection unexpected
+3
source share
1 answer

Dash does not support process overriding ( <()).

The behavior you see is consistent if you use syntax that is supported by each of the shells you are comparing. Try the following:

echo hello | cat < inputfile

You should see the contents of the "inputfile", not the "hello". Of the few shells I tried, only the Z-shell showed both.

This is what POSIX says about pipelines and redirects:

1 2. , , , (. ).

, stdin cat, .

+3

Source: https://habr.com/ru/post/1784091/


All Articles