Using $PROMPT_COMMAND to beep depending on success/failure

Tim Chase blinux.list at
Wed Apr 20 18:41:11 UTC 2016

Stumbled on this one today thanks to @climagic on Twitter.  If you
want to have your machine give you one tone if the previous command
succeeded (had an exit-status of 0) and a different tone if the
previous command failed (had a non-zero exit status), you can put the
following one-liner in your .bashrc file:

PROMPT_COMMAND='[ "$?" == 0 ] && play -qn synth sin F3 trim 0 0 0.1
fade 0 0.1 0.05 vol 0.2 || play -qn synth square F4 trim 0 0.1 fade 0
0.1 0.05'

This uses the `play` command from the `sox` package.  There are a
number of tweaks you can make to change the tones, timbres,
wave-form, volume, duration, etc.  The above uses an F3 sine-wave at
20% volume for success and an F4 square-wave at 100% volume for

To test it out, use the `true` and `false` commands (they don't do
anything other than exit with a particular zero/non-zero exit code).

But here's hoping someone here finds it useful.


More information about the Blinux-list mailing list