1

How can I customize bash to add a system “bell” whenever a readline (prompt user for input) is requested?

Running (upgraded) bash 4.1.0 on Mac OS X 10.6 (Snow Leopard).

1 Answer 1

4

Add \[\a\] to PS1 (normal prompt) and PS2 (continuing prompt), e.g.

PS1="\u@\h\[\a\] "

will make the normal prompt

username@hostname

including a bell.

\a is the BELL character, \[ and \] tell the shell it's not printed (for width calculation).


Add the PS1=... line to ~/.bash_profile once you're happy with it.


This doesn't work for command-line based applications though. I don't think it's possible, since you can enter quite often input even while output is being printed; this accumulates. And a prompt just means nothing's currently writing to the terminal.

3
  • Yeah, I don’t want a bell on my PS1 prompt. Basically, I’d like a bell if something is waiting for readline input.
    – Zearin
    Apr 30, 2011 at 13:00
  • But close enough, I suppose. Maybe if I add this to one of the other PS# variables. I’ll have to check. (Anyway, thanks! ☺)
    – Zearin
    Sep 6, 2011 at 12:41
  • 2
    @Zearin I also found out since, that there is PS3 used for actual prompts in bash scripts.
    – Daniel Beck
    Sep 6, 2011 at 12:47

You must log in to answer this question.

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