how to execute command after current running command in bash?
Solution 1:
You can do something like this:
- stop execution of wget with ctrl-z (it's not stopped, it's suspended)
- put it into background (bg)
- run: wait; shutdown -h now
wait will wait for all programs ran in background from current shell - i.e. this wget.
After wait will finish - shutdown will go on.
Solution 2:
In another shell, use
ps -u <your username> | grep wget
to find the PID of the command you want to wait on, then
wait <PID>; shutdown -h now
so that shutdown will not run until process has terminated. See also depesz's answer.
Solution 3:
My solutions is this: suspend your long-running task with Control+Z, then type something like:
fg; echo "Done!"
If you want to run react differently based on the success or failure of your command, use && and || as short-circuit operators.
fg && echo "Success!" || echo "Failure!"
EDIT: This won't work with sudo, because it will ask for your password. I have, accordingly, removed the examples using sudo. If you need sudo for the second task, use another of the methods posted here.
On the other hand, I believe that both GNOME and KDE offer ways to trigger a shutdown/reboot without using sudo, by sending an appropriate D-Bus signal or something.