Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 插入带有特殊字符的变量_Bash_Shell - Fatal编程技术网

Bash 插入带有特殊字符的变量

Bash 插入带有特殊字符的变量,bash,shell,Bash,Shell,在我的shell脚本中,如果没有特殊字符,如“或\/ mysql -e" insert into test.mycron values ('$myhost', '$myfile')" 如何将整个变量“$myfile”与特殊字符一起保存?您必须转义这些字符,例如使用sed,类似于: myhost="$(echo "$myhost" | sed 's/\(['"'"'\]\)/\\&/g')"

在我的shell脚本中,如果没有特殊字符,如“或\/

mysql -e" insert into test.mycron values ('$myhost', '$myfile')"

如何将整个变量“$myfile”与特殊字符一起保存?

您必须转义这些字符,例如使用sed,类似于:

myhost="$(echo "$myhost" | sed 's/\(['"'"'\]\)/\\&/g')"