I`m trying to add variable using docker CLI command in following way:
docker exec -u root airflowdags_webserver_1 bash -c "airflow variables --set my_var '{\"test\": \"test\'2\"}'"
But getting following error:
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
I have no any errors if doing one of these commands:
docker exec -u root airflowdags_webserver_1 bash -c "airflow variables --set my_var '{\"test\": \"test\`2\"}'"
or
docker exec -u root airflowdags_webserver_1 bash -c "airflow variables --set my_var '{\"test\": \"test2\"}'"
How can I escape apostrophe in the "test'2" value to avoid the error?
A bash single quoted string cannot contain a single quote. You can't escape it. (ref https://www.gnu.org/software/bash/manual/bashref.html#Single-Quotes)
Try this:
bash -c "airflow variables --set my_var '{\"test\": \"test'\''2\"}'"
# .......................................1.................1..2....2
I numbered the matching single quoted strings. In between is a literal single quote.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With