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

How to escape single and double quotes in bash

I have a script that takes text as an argument and encodes it. If the text contains only single quotes I surround it with double and vice versa, but it gets tricky if it contains both because it will be closed at first appearance.

script "I can't use "test" text"
// Double quote will be terminated at "I can't use "

So how to escape both cases without using a backslash, like in python using triple single, or double quotes.

script '''I can't use "test" text'''
// or
script """I can't use "test" text"""

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 :

Use a here-document, and use command subsitution to turn it into an argument.

script "$(cat <<'EOF'
I can't use "test" text
EOF)"

Or

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