-1

The echo command doesn't want to interpret backlash escapes (with -e option attached). For example, I want it to ring a bell with: echo -e \a

Nothing happens, except it prints: a or \a

How to turn on interpreting or how to fix it?

7

In echo -e \a the \ in front of the a will be stripped off from the argument to echo by the shell before echo is called. It is exactly equivalent to

echo -e 'a'

For echo to receive \a as backslash-followed-by-a, the \ has to be passed as is to echo. This is done either through

echo -e '\a'

or

echo -e \\a

If this will actually produce an audible or visible bell may depend on other settings.

  • 1
    ~/.inputrc is to configure readline, it doesn't affect the terminal behaviour when you send a BEL character to it. – Stéphane Chazelas Feb 20 '18 at 19:50
  • @StéphaneChazelas Hmm... I wonder why I don't get any bells then. Is it because I run tmux? But readline would at least control the shell's bells? – Kusalananda Feb 20 '18 at 20:29
  • 1
    Yes, readline's bell-style would control whether readline sends a \a (BEL) or a visual bell escape sequence or nothing to the terminal when it wants to notify the user. – Stéphane Chazelas Feb 20 '18 at 22:55
  • 1
    See also Why Ctrl+G doesn't produce a beep? – Stéphane Chazelas Feb 21 '18 at 8:36
3

You need to protect the \ from being interpreted by the shell. Try this:

echo -e '\a'

or

echo -e \\a

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.