4

How can I make ring the bell from command line using WSL (2)?

I tried:

beep
echo -ne '\007'
echo -e "\a"

I have set bellstyle none in /etc/inputrc.

Using Ubuntu 18.04 image.

2
  • 2
    Uhh why did you set bellstyle none if you want the bell to ring? echoing the bell character in my WSL produces the default windows "ding"
    – Panki
    May 7 '20 at 19:50
  • 1
    I don't want the shell to beep all the time, it is super annoying and should be turned off by default IMO. Though I would like to start a long lasting process and then play a sound, so I know when it is finished and don't have to check visually all the time. E.g. I can go read something.
    – Soren
    Dec 14 '20 at 19:50
7

In WSL Ubuntu or Alpine with default path setup, you can depend on .net's Console.Beep method:

powershell.exe '[console]::beep(261.6,700)'

It makes a handy alias for etc/profile or ~/.bashrc:

alias bloop="powershell.exe '[console]::beep(261.6,700)'"

Define a helper function to create multiple tones:

_beep () {
  powershell.exe "[console]::beep($1,$2)"
}

alias bleep="_beep 1000 800"  # A strong bleep (for profanity)
alias  beep="_beep 2000 300"  # Quick yet noticeable beep
alias  blip="_beep 4000  80"  # A less distracting blip

Example: Blip on success, but bleep on failure:

make && blip || bleep
2
  • If PATH is broken, it might be due to these (1, 2) WSL settings. In a pinch, adding /mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/ to the path may fix the issue
    – Max Suica
    Dec 12 '20 at 1:22
  • It works ! :-).
    – Soren
    Aug 24 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.