In a bash script/command how can I make a PC beep noise, or play a sound file?

Viewed 91414

I have some long running scripts with breaks requiring input/interaction to continue but when I switch to another window I'd like to be notified (by sound) that a task is complete and now awaiting input.

I would prefer to be able to play an audio clip (*.mp3, *.ogg, etc.) but wouldn't care if the only solution is to make the PC Speaker beep noise.

Any ideas? I'm open to any CLI utilities I can install that play sounds that in turn I can execute when needed.

FYI: My System is running WinXP Pro.

UPDATE: Doh! My Windows > Control Panel > Sounds > Default Beep: was set to (none). Grrr...

Problem solved.

9 Answers

This will make a beep from within bash

echo -en "\007"

Try this:

echo ^G

(^G is obtained by ctrl+G).

Note: you can't copy and paste this code in a batch file, it won't work. To obtain a ^G character in a file, type in a cmd window:

echo ^G > beep.txt

(again, ^G is obtained by ctrl+G).

Then you'll have a file named beep.txt, open it with notepad, there will be a square character. This is our ^G once it is saved in a file.

You can then copy and paste it in a batch file to make a sound (don't forget to put "echo" in front of it).

I know your question was for Window but just putting this here for any Mac OSX users who come across this article. OSX 10+ comes with the say command:

say "I'm done"

For example:

sleep 5 && say "I'm done waiting 5 seconds"

Simple answer without ^G

echo -en "\007"

In my bash profile I've added a BEEP to the script using @GregReynolds solution above then added this to PS1:

GREEN="\[\033[0;32m\]"
BEEP=$(echo -en "\007")
export PS1="$GREEN : ${BEEP}"

source ~/.bash_profile - you should hear the beep after the command prompt returns

I have git-autocomplete on usually so I've provided a much simplified version above

Related