Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape apostrophe in docker command

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?

like image 880
Valerii Fludkov Avatar asked Aug 30 '26 11:08

Valerii Fludkov


1 Answers

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.

like image 184
glenn jackman Avatar answered Sep 01 '26 01:09

glenn jackman