Writing in bash while it is working
When you are performing time consuming operations in bash like installing new software, is it possible to write text that will appear at the prompt when the operation has finished.
E.g
Imagine running:
apt-get install eclipse-platform
Then it will use quite a while to finish while you see the installation log, meanwhile I want to create new folders (workspaces) which Eclipse later will use.
Is this possible without opening a new terminal (or tab)?
You can run the installation in the background. This leaves the foreground free for you to type further commands. You will be notified when the background job has finished.
Check the man page for apt-get and look for options that make it work quietly without writing lots of output. Check for options that make it work without requiring user input (e.g. confirmations)
Use redirection to have apt-get write messages and errors to files, use the ampersand suffix to run the command in background
nohup apt-get --be-quiet --dont-ask \
install eclipse-platform > agiep.out 2>agiep.err &
You probably dont need nohup
(see man page). I invented --be-quiet
and -dont-ask
so check man apt-get
for real equivalents (if any).
See also fg
in your shell's man-page.
Note: many of the above features are shell-dependent. Should be OK in bash, ksh and their ilk.
If the program in question doesn't consume stdin then you can enter commands followed by Enter and have them executed after the program finishes (and as long as none consume stdin).
There are many ways to accomplish this.
You can pause a task at anytime by pressing ctrl + z. Then, to resume the task in background, use the command bg. You can bring a task back to foreground with fg
Therefore, if apt-get is running, do ctrl+z , then run bg. this will make it run in background.
You could also read on screen or byobu.
One handy alias that comes with ubuntu's .bashrc (I don't know if it also comes in debian) is this one:
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
It uses notify-send (desktop environment): With notify-send you can send desktop notifications to the user via a notification daemon from the command line. These notifications can be used to inform the user about an event or display some form of information without getting in the user's way.
You can issue your command in a subshell in the background so you can continue doing things in that shell. Also you can add checks to get different messages if the command went OK or not:
( sleep 5 && alert "sleeped OK" || alert "something nasty happened with sleep") &