Suppose you want to have a program that ingest a string and then reattach
stdin when done.
I know that it is possible to do so by doing this trick:
(echo id; cat) | sh
Which works well. It doesn't close
stdin since it is used by
cat. But the output is messy.
Digging deeper I understood that it is lacking of a
If my comprehension is right,
sh being in a pipe didn't open a
The trick I've found is to use
Simply put this in a file:
spawn sh reattach
cat gives you back the control, do:
This is nice because it gives me a
tty to do everything I need:
tmux and so on...
The only thing I don't understand why is that I see everything I typed, back to my terminal.
(echo whoami; cat) | sh moon expect exp.sh spawn sh sh-3.2$ whoami whoami moon
whoami output back before my login on the last line.
Could somebody explain to me why? It is obviously not a property of
cat because it is attached to
sh directly -- yes, even if it was dumb I tried the following:
(echo id; cat > /dev/null) | sh then nothing happened.
So is it a property of a
pty to not display back what has been typed from the keyboard?