Friday, December 02, 2022

Re: redirection puzzle

On Fri, 2022-12-02 at 16:17 +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...

tty(1) is one of the shorter applications, so it's easy to see what it
does:
t = ttyname(STDIN_FILENO);
if (!sflag)
puts(t ? t : "not a tty");

Since $(tty) is part of the chain now, so stdin is the output of echo
and the output will be "not a tty". You might have some additional files
laying around. :-)

martijn@
>
> Thanks for any comments (and sorry for such a trivial
> question).
>
>
> Best regards,
> Ruda
>

No comments:

Post a Comment