Escape single quote within double quote within single quote

This question already has an answer here:

  • How to escape single quotes within single quoted strings? 19 answers

  • A simple advice: when in doubt and no special needs that force you to use both single and double quotes, just normalize the quotes and escape the inner ones:

    curl -X POST --data-urlencode "payload={"channel": "@somebody", "text": "I'm sending you a test message. Let me know if you get it."}" https://hooks.slack.com/services/XXX
    

    It's cleaner and intuitive.

    If you want to really escape the single quote inside double quotes:

     curl -X POST --data-urlencode 'payload={"channel": "@somebody", "text": "I'''m sending you a test message. Let me know if you get it."}' https://hooks.slack.com/services/XXX
    

    Without any escaping etc you can use here-doc and pass it to your curl command:

    cat<<-'EOF' | curl -X POST --data-urlencode @- https://hooks.slack.com/services/XXX
    payload={"channel": "@somebody", "text": "I'm sending you a test message. Let me know if you get it."}
    EOF 
    

    Here @- will make curl read data from stdin.

    链接地址: http://www.djcxy.com/p/57130.html

    上一篇: 在bash字符串中写入特殊字符

    下一篇: 在单引号内双引号内退出单引号