74

I'm using some Bash scripts under Linux that require some time to complete; I'd like to add at the end of them a command to ring the system bell when those tasks are done, so I can be notified.

What's the proper command to do that? (please note that what I need is to be notified, with a sound and possibly with a message, so I can accept any solution in these regards).

9
  • 14
    Downvoting without an explanation is not very useful...
    – Sekhemty
    Sep 6, 2015 at 14:19
  • unix.stackexchange.com/q/1974/1932
    – paradroid
    Sep 6, 2015 at 14:19
  • 3
    These solutions aren't working for me.
    – Sekhemty
    Sep 6, 2015 at 14:27
  • 5
    What does your research tell you? What exactly have you tried and what didn't work?
    – slhck
    Sep 6, 2015 at 14:41
  • 4
    ( speaker-test -t sine -f 440 )& pid=$! ; sleep 0.4s ; kill -9 $pid requires ALSA installed. Always from one of that answers
    – Hastur
    Sep 8, 2015 at 13:20

2 Answers 2

83
tput bel

is a relatively portable solution.

6
  • "tput bel" works on macOS, as it should. Dec 14, 2017 at 15:46
  • Works on Cygwin bash terminal as well.
    – ysap
    Aug 10, 2018 at 17:25
  • Works on CentOS 7 bash via macOS terminal.
    – rinogo
    Sep 3, 2020 at 14:59
  • 2
    Doesn't work on Ubuntu 22.04.
    – Coder
    Jan 25, 2023 at 4:14
  • 1
    Works for me on Ubuntu 22.04.
    – LovesTha
    Sep 7, 2023 at 9:35
35

Try this command:

echo -e "\07"

or

echo -e "\a"

They are the same. "07" is an octal representation of BEL (bell) character in ASCII, and "a" stands for "alert", the letter is probably easier to remember. As mentioned in the comments, the -e switch enables escape sequences. Also, you can append a message directly after the escape character like this: "\aSuccess!".

4
  • 2
    N.B. The -e is needed to enable interpretation of the \07 escape sequence. Nov 27, 2017 at 11:20
  • Works on Cygwin bash terminal as well.
    – ysap
    Aug 10, 2018 at 17:25
  • 1
    replacement for -e is dollor sign: echo $'\a' Apr 5, 2023 at 17:46
  • 1
    @PeymanMajidi The $'\a' format is a function of the shell, not the echo command; I'm guessing some shells won't support it. Jan 5 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .