37

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 where contents of ./ringbell 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 to 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?

The ubuntu version of screen package I have is 4.1.0~20120320gitdb59704-9.

Bob
  • 605
  • 1
  • 5
  • 13
  • 1
    Also refer to [this question](http://unix.stackexchange.com/q/1974), although I actually prefer Keith's answer. – Franklin Yu Jul 09 '16 at 04:28

2 Answers2

58

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

Keith Muggleton
  • 696
  • 6
  • 2
  • This doesn't work either inside or outside of screen. If I use infocmp it shows me that the bel capability is not defined for TERM konsole-256color so this makes sense. Although the screen terminfo entry defines bel a tput -T screen bel also does not work. – Bob Sep 03 '14 at 12:06
  • 1
    After more testing it appears tput -T screen bel does work after all. My initial test failed because I was running a screen within a screen and the outer screen did not have vbell off. Thanks for the the tip. – Bob Sep 03 '14 at 13:51
  • This does not work inside a `screen` session on a remote server logged in via ssh – user5359531 Mar 03 '22 at 16:08
12

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'

Bielecki
  • 13
  • 3
Pi Marillion
  • 221
  • 2
  • 3