45

In a konsole terminal window outside of screen running a bash shell with TERM set to konsole-256color if I type:

echo -n $'\a'

or

echo -n $'\eg'

or

./ringbell.sh

where contents of ringbell.sh is

#!/bin/bash
echo -n $'\eg'
echo -n $'\a'

They all result in the configured audio bell going off. If I enter a screen session (my ~/.screenrc also sets TERM=konsole-256color) only the second of the above 3 commands (echo -n $'\eg') result in the audio bell being heard. Do I have to modify the script or is this an issue with screen?

I use screen 4.1.0~20120320gitdb59704-9 from Ubuntu.

pevik
  • 600
Bob
  • 705

3 Answers3

66

From memory, Ctrl-G is the bell character, so I think that's why the second one worked. But screen can be picky over what characters it accepts as it takes Ctrl-A as the command code.

Try this

#!/bin/sh
# Ring the terminal bell
# echo "\a" # does not work in some shells
tput bel

I found this on rosettacode, hopefully it will give you some options

16

Best solution: printf '\a'

That's because the printf built into most shells works well, and there's also an equivalent executable version of printf installed with Linux/Mac systems.

Other options: If you have curses installed, then you can also use: tput bel If you use a recent version of bash, then you can use: echo -e '\a'

0

What works for me is adding vbell off to ~/.screenrc, then all the tput bel terminal bell rings come through from my scripts/commands when I'm in screen too. (I'm on Ubuntu 22.04 Server).

Thanks @Bob for mentioning it.