Hacker News new | ask | show | jobs
by kuwze 2668 days ago
Disclaimer: I am an idiot on this subject

I recently found out that you can’t easily spawn a shell and then send commands to it. It’s doable with tmux commands, but you’d think it would be easier. I just wanted to write something that locates npm/virtualenv stuff in bash, nothing fancy.

7 comments

A distinction you may be having trouble with, because it's kind of hidden from the user, is the difference between a shell and a "pty" (pseudo teletype). You certainly can spawn a shell and send it commands, but because it doesn't have a pty the input is treated very differently.

That's what you get setup for you by running tmux, screen, expect, xterm, ssh etc.

(Bonus: https://askubuntu.com/questions/481906/what-does-tty-stand-f... )

"expect" was mentioned, but what are you actually trying to do that cannot be solved with a shell script, either executed the normal way or sourced in at the start of a new shell?
wow I feel like an idiot, thank you.
Just to join in the "I feel like an idiot" fun: yea, I've used tmux to do this too. First I've heard of `expect`. TIL.

Bash is pretty bad at helping you discover how to do things.

Why can't you run a shell script?
I think you want expect.
wow I feel like an idiot, thank you.
No, you are most likely not, but you are also not likely looking for expect.

It sounds like you are doing something simple in a very roundabout way. Explain instead the intended outcome and many people will be happy to help.

What do you mean by locates?

  echo ls | bash
It even seems to work with named pipes, although in my first test it exited after the first command (I suspect I'm accidentally sending a EOF when I echo the command in).

    mkfifo testpipe1
    <testpipe1 bash  # in separate window
    echo ls > testpipe1
If you have echo and a pipe, then you're most likely already in a shell, no?