I am experimenting with exec'ing bash itself only to redirect output. If I use redirection like
exec >bla.log ls exec 1>&2
It works as expected: the ls output ends in bla.log , and after the second exec everything returns to its normal state, mainly because descriptor 2 is still bound to the terminal.
Now I decided to send the result through the channel, and not to the file, a trivial example - exec | cat >bla.log exec | cat >bla.log . However, the team returns immediately. To find out what happens, I did the following:
exec | bash -c 'echo $$; ls -l /proc/$$/fd /proc/23084/fd'
where 23084 - this bash is currently working and got this:
24002 /proc/23084/fd: total 0 lrwx------ 1 harald harald 64 Aug 14 20:17 0 -> /dev/pts/1 lrwx------ 1 harald harald 64 Aug 14 20:17 1 -> /dev/pts/1 lrwx------ 1 harald harald 64 Aug 14 20:17 2 -> /dev/pts/1 lrwx------ 1 harald harald 64 Aug 14 20:17 255 -> /dev/pts/1 /proc/24002/fd: total 0 lr-x------ 1 harald harald 64 Aug 14 21:56 0 -> pipe:[58814] lrwx------ 1 harald harald 64 Aug 14 21:56 1 -> /dev/pts/1 lrwx------ 1 harald harald 64 Aug 14 21:56 2 -> /dev/pts/1
As we can see, subprocess 24002 really listens for the pipe. But this, of course, is not the parent process, 23084, which opens this channel.
Any ideas on what's going on here?
bash io-redirection
Harald
source share