Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does "echo" default to "echo -e" in bash 5.1.12?

I stumbled upon a weird problem with echo on GNU bash, version 5.1.12(1)-release (x86_64-pc-solaris2.11):

bash-5.1$ builtin echo -e 'a\tb'
a       b

bash-5.1$ builtin echo 'a\tb'
a       b

bash-5.1$ builtin echo +e 'a\tb'
+e a    b

While it won’t affect my scripts because I tend to use printf, how do you turn echo -e off?


not a dup (I think): The question isn’t about the behaviour of echo in an arbitrary shell but in bash specifically.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have the xpg_echo shell option enabled.

List the options by running shopt

Disable it with shopt -u xpg_echo

To figure this out, read the echo section of man builtins (assuming that gives you the bash builtin commands, otherwise look at https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html)

The relevant part is

The xpg_echo shell option may be used to dynamically determine whether
or not echo expands these escape characters by default.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading