Friday, December 02, 2022

Re: redirection puzzle

Martijn van Duren <openbsd+misc@list.imperialat.at> wrote:
> >
> > odin:~$ echo 1 | tee $(tty) | sed 's/1/2/'
>
> 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. :-)

So this is probably the way, right?

odin:~$ A=$(tty) echo 1 | tee $A | sed 's/1/2/'
1
2
odin:~$

Thanks.

Ruda

No comments:

Post a Comment