docker命令中的撇号撇号

我正尝试用以下方式使用docker CLI命令添加variables:

docker exec -u root airflowdags_webserver_1 bash -c "airflow variables --set my_var '{\"test\": \"test\'2\"}'" 

但得到以下错误:

bash:-c:第0行:寻找匹配时出现意想不到的EOF`“'

bash:-c:第1行:语法错误:意外的文件结束

我没有任何错误,如果执行这些命令之一:

 docker exec -u root airflowdags_webserver_1 bash -c "airflow variables --set my_var '{\"test\": \"test\`2\"}'" 

要么

 docker exec -u root airflowdags_webserver_1 bash -c "airflow variables --set my_var '{\"test\": \"test2\"}'" 

我怎样才能在“test'2”值中撇开撇号以避免错误?

bash单引号string不能包含单引号。 你不能逃避它。 (参考https://www.gnu.org/software/bash/manual/bashref.html#Single-Quotes

尝试这个:

 bash -c "airflow variables --set my_var '{\"test\": \"test'\''2\"}'" # .......................................1.................1..2....2 

我编号匹配的单引号string。 中间是一个字面的单引号。

Interesting Posts