Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to automate something writing simple script launching consecutively few scripts one after another. And then setting some aliases at the top shell.
Problem: few of these commands launch new shell. And all commands after that one are launched in previous shell. Is there anyway to queue these commands coming after that one in "top" shell?
Simple Example:

#normally this ksh is executed deep inside other script i cannot modify
echo test

Is there any way to print "test" on shell just started by ksh command? Normally test is printed in previous shell - becomes available after "exit" command Thanks for any help.

share|improve this question
Your use of "top shell" is slightly confusing. You mean the last subshell that you started, right? – Uwe May 23 '13 at 13:03
yes, thats correct. – Aleksander Fular May 23 '13 at 13:45
up vote 0 down vote accepted

Four alternatives, but each of them has a drawback:

  1. Make sure that the commands that you want to execute in the ksh are written to the file mycmds and start the ksh in the following form:

    cat mycmds /dev/tty | ksh -i

    Drawback: You lose the command-line editing features of ksh.

  2. Make sure that the commands that you want to execute in the ksh are written to the file /tmp/mycmds$$; set the environment variable MYCMDS to /tmp/mycmds$$ before starting ksh -l; and add the following to your $HOME/.profile:

    if [ -n "$MYCMDS" ] ; then
        . "$MYCMDS"
        export MYCMDS

    Drawback: Everybody who uses this program has to modify his $HOME/.profile.

  3. Organize the entire thing in such a way that the commands you want to execute are written to a file mycmds which is then sourced via . mycmds in the initial shell. Put all that into a function definition.

    Drawback: Rather than starting a new shell, you modify the environment and/or alias definitions of the initial one. Everybody who uses this program has to use ksh.

  4. Make sure that the commands that you want to execute are written to the file mycmds and start a bash in the following form:

    bash -i --init-file mycmds

    Drawback: You get a bash instead of a ksh.

share|improve this answer
lshmm, the result is almost what i want when i use : ( cat mycmds /dev/tty ) | ksh (without the -i ). But the prefix before.. dont know how this is called before -> "you can type here" no longer appears – Aleksander Fular May 23 '13 at 14:57
It's called "prompt". Without -i or -l, a ksh that reads from a pipeline is not an interactive one (man ksh), which means in particular that there is no prompt. – Uwe May 23 '13 at 14:59
By the way, the parentheses around cat mycmds /dev/tty are useless. Originally, I had two commands here; after deleting one of them I should also have deleted the parentheses. – Uwe May 23 '13 at 15:04
Hmm, ok. However when i use the -i. that shell window is "stuck" it does not accept commands anymore. or should i say it doesnt responds anymore. And without the -i option ( no longer interactive ) my .profile aliases arent visible in this new shell. – Aleksander Fular May 23 '13 at 15:16
You're right about the problems with -i, and the version without this option doesn't work well either. I'd go for method 2 or 4 (2 is essentially an emulation of the bash --init-file option.) – Uwe May 23 '13 at 18:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.