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

Bash initialize variable to a string that contains quotes and backslahes

I have a string containing quotes and backslahes:

-options \'{"version": "http"}\'

I would like to initialize a variable PARAM with this string.
How this can be done in bash?

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

I thought of adding it to an array: PARAMS=(-options \'{"version": "http"}\')

but the output I am getting is: -options '{version: http}' i.e. without the slashes.

Expected output: -options \'{"version": "http"}\'

Can someone please suggest?

>Solution :

This looks ok to me.

test="-client-options \\'{\"quic-version\": \"h3\"}\\'"
echo "$test"
t2=("$test" "etc")
echo ${t2[@]}

Escape every inner " and double escape for a persisting escape

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