Friday, December 02, 2022

Re: redirection puzzle

On Fri, Dec 02, 2022 at 16:17:18 +0100, rsykora@disroot.org wrote:
> Dear list,
>
>
> I needed to show the stdout of a command as well as pass
> it to another command's stdin. This works:
>
> odin:~$ echo 1 | tee /dev/stderr | sed 's/1/2/'
> 1
> 2
> odin:~$
>
> and this works, too:
>
> odin:~$ echo 1 | tee /dev/ttyp8 | sed 's/1/2/'
> 1
> 2
> odin:~$
>
> where /dev/ttyp8 is the result of the tty command:
>
> odin:~$ tty
> /dev/ttyp8
> odin:~$
>
> but this does not work:
>
> odin:~$ echo 1 | tee $(tty) | sed 's/1/2/'
> 2
> odin:~$
>
> I do not understand why...
>
> Thanks for any comments (and sorry for such a trivial
> question).

I tend to get fed up with the shell when debugging things like this and
will instead start building a script in another language. perl is in
base, and there are dozens of others in the ports collection, all of
which have more robust and clearer handling of file descriptors than the
shell.

--
Cheers,
luna

No comments:

Post a Comment