14

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
    Commented May 7, 2020 at 19:50
  • 2
    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.
    – Soerendip
    Commented Dec 14, 2020 at 19:50

1 Answer 1

20

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
    Commented Dec 12, 2020 at 1:22
  • It works ! :-).
    – Soerendip
    Commented Aug 24, 2021 at 22:10

You must log in to answer this question.

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