I would like to undestand where a stdin redirection goes in an expression like < <(cmd)
as a test to learn more about bash I tried to write a bash function with while .. do .. done
and to have it working I had to use a trial and error method , mainly because I did not know the behavior or the first redirection in < <(find ...)
:
while read L ;do basename "$L";((k++));done < <(
find -maxdepth 1 -type d -name '.*' |
sort
)
With only <(find ...
it does not work . I suppose it's because stdout of find
command line goes to a tmp file ( so I read ) ; so I added one more <
to "push" further the copy of stdout . That I can understand , but how can I know that stdout copied in the tmp file does not stop at the first command encountered : basename
and goes as far as stdin of while
command ?
<(...)
alone is not a redirection; it's a process substitution, that exposes the output of a command as if it were a file. the<
betweendone
and the process substitution is the redirection operator: it causes thewhile
loop to use the process substitution as its standard input.while
loop inherits the loop's standard input as its own, which is why eachread
command reads from the process substitution as well.