Knowledge Base:Shutdown after emerge

Emerge is not running
This command shuts down the computer only if emerge finishes successfully, it also saves a log to emerge-log.log in the current directory that you can read when you turn on the computer again. For example for updating and shutting down we have:

If you want to turn off the computer only if emerge quits successfully:

KDE
If you are using KDE, it may be a good idea to have kde logout first before the shutdown process begins. To do this, type:

Emerge is already running
If emerge is already running, hit ctrl-z. The process will be paused

[1]+ Stopped                 emerge kdebase-meta

Now type

bg resumes executing of emerge in the background. wait waits for last command sent to background to terminate. When emerge finishes with success, poweroff command will be executed.

Another Way
You can accomplish the same thing by pausing the process with ctrl-z as described above and then typing this:

or

This continues the paused process and after this process finishes it continues the next command (poweroff) ...

It is important to notice that && will only continue with the next command, if the first command completed successfully. && is the logical AND operator of the shell. By using ; the next command will be executed no matter what happend earlier. ; is only a command seperator.

A variant of this can be used to play a sound when emerge is done.

The fg variant is a little more straight forward probably.

Resources

 * Gentoo Froum
 * Archive of Older Gentoo Wiki