How can I escape a double quote inside double quotes?

后端 未结 8 1505
庸人自扰
庸人自扰 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条回答
  •  心在旅途
    2020-11-22 16:47

    A simple example of escaping quotes in the shell:

    $ echo 'abc'\''abc'
    abc'abc
    $ echo "abc"\""abc"
    abc"abc
    

    It's done by finishing an already-opened one ('), placing the escaped one (\'), and then opening another one (').

    Alternatively:

    $ echo 'abc'"'"'abc'
    abc'abc
    $ echo "abc"'"'"abc"
    abc"abc
    

    It's done by finishing already opened one ('), placing a quote in another quote ("'"), and then opening another one (').

    More examples: Escaping single-quotes within single-quoted strings

提交回复
热议问题