Bash initialize variable to a string that contains quotes and backslahes

Viewed 22

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?

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?

1 Answers

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

Related