Ctrl+Z and fg to append commands
- by avilella
I would like to know what is the behaviour of Ctrl+Z and fg in bash when wanting to append commands to be executed after a running command has finished. For example, in the sequence for commands below, I would expect the console to display "1", then "2", then "3", then "4", but I only get the last command, echo 4, after sleep 30 finishes:
avilella@magneto:~$ sleep 30 && echo 1
^Z
[1]+ Stopped sleep 30
avilella@magneto:~$ fg && sleep 5 && echo 2
sleep 30
^Z
[1]+ Stopped sleep 30
avilella@magneto:~$ fg && sleep 5 && echo 3
sleep 30
^Z
[1]+ Stopped sleep 30
avilella@magneto:~$ fg && sleep 5 && echo 4
sleep 30
4
Any ideas?