Just to say it up front: I am aware that most programs that have an interactive prompt also have some kind of initialization file or the ability to set a command flag that will run something, and then drop you into the interactive prompt. However, I'm interested in the solution at the shell level.
Let's say I have a command
xyz that I run from a shell, and it takes over my terminal and gives me an interactive prompt where I can run newline terminated commands.
Let's say I have two commands (two lines) I want to run at the beginning of my interactive session, each and every time I run
If these two lines were the only commands I wanted to run, of course I could just run:
printf '%s\n' 'first command' 'second command' | xyz
Or alternatively, if I had a whole bunch of commands to run but I know all of them in advance, I could just put them all in a file and run:
xyz < commands-file.txt
However, if I want to get a standard interactive prompt, with the exact same result as if I typed
xyz and then manually typed in my
first command and
second command...is there a way to do this in the shell (e.g. in a shell function) using redirection?
The obvious apparent solutions such as
sed -e '1ifirst command' -e '1isecond command' | xyz don't work, either because
xyz can detect that the input is not coming from a terminal or because the
sed output is buffered; not sure which.