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 do bash single quotes interpret "\n" as newlines?

According to documentation, single quotes in bash preserve all literal characters, however the following:

echo 'a\nb'

Outputs:

a
b

(i.e. the literal \ and n have been replaced with a newline)

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

Why is this the case? (what am I missing?)
Also, what other characters does this affect?

For reference I’m using GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22)

>Solution :

bash doesn’t. echo does. But if you had written it as $'a\nb', bash would have done the interpretation.

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