0

It often happens that I have some long task running, like compiling a program, running tests or copying large archives. Once I am done with whatever else I was doing, I want to leave the computer unattended and have it shutdown or hibernate once it was done whatever it was doing.

To achieve this, I learned that I can suspend the process, then chain the fg command, e.g. fg && shutdown. What if I change my mind and no longer want the other command to run?

I believe the fg part is mostly irrelevant here, and the question boils down to how in foo && bar prevent bar from running while allowing foo to finish.

New contributor
Dominik Kaszewski is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

1 Answer 1

0

Just do Ctrl+z upon which fg will return with an exit code of 128+SIGTSTP, so not 0/success, so shutdown won't be run, and then fg again without a && shutdown this time.

Example:

bash-5.3$ sleep 10
^Z
[1]+  Stopped                    sleep 10
bash-5.3$ fg && echo would shutdown
sleep 10
^Z
[1]+  Stopped                    sleep 10
bash-5.3$ fg
sleep 10
bash-5.3$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.