How can I escape a double quote inside double quotes?

后端 未结 8 1621
庸人自扰
庸人自扰 2020-11-22 15:56

How can I escape double quotes inside a double string in Bash?

For example, in my shell script

#!/bin/bash

dbload=\"load data local infile \\\"\'gfp         


        
8条回答
  •  猫巷女王i
    2020-11-22 16:23

    Check out printf...

    #!/bin/bash
    mystr="say \"hi\""
    

    Without using printf

    echo -e $mystr
    

    Output: say "hi"

    Using printf

    echo -e $(printf '%q' $mystr)
    

    Output: say \"hi\"

提交回复
热议问题