3

If you want to execute one command and then another one after the first one finish, you can execute

command1 & 

which prints the PID of the process executing command1.

You can then think of what you want to do after command1 has finished and execute:

wait [PID printed by the previous command] && command2 

However, this only works in the same terminal window and gets really, really messy if command1 prints output. If you open up a new terminal window and try to wait, you're shown something like this:

$ wait 10668 bash: wait: pid 10668 is not a child of this shell 

Is there a terminal emulator which supports waiting for programs without having to write the next command in the output of the currently executing command without throwing the output of the first command away (like piping it to /dev/null)?

It doesn't have to work via wait or something similar. Right-clicking and choosing "execute after current command returned" would be perfectly fine.

I don't mean simply concatenating commands but being able to run a command and then decide on what to run right after that one finished.

0

2 Answers 2

2

Often, having given a long-running command, when you want to prepare the next command to run afterwards, you use shell job control to achieve it. Eg, you have given command1, not with an &, and then you want to give command2, so you suspend the current running command by typing control-z. You now have the shell prompt again, so you type

fg; command2 

and the fg will resume your first command, and when it finishes the shell will start your second command.

If you did start command1 with &, it is in the background. You can bring it to the foreground with fg, then suspend it and so on as before.

1

If you just want to run commands as soon as the previous one has completed, you can separate them with ; like this:

command1 ; command2 

Or, if you only want to run the second command if the first command returns true, like this:

command1 && command2 
1
  • Perhaps I should have added that this is not what I want. Well, I use it a lot but it's not what I'm asking this question for. It's about when I don't yet know what the next step will be. Commented Apr 11, 2016 at 0:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.