Why does sed require 3 backslashes for a regular backslash?

后端 未结 7 1638
余生分开走
余生分开走 2020-11-29 01:26

I\'m curious, why does sed need 3 \\ just to recognize one? I\'d understand it needing 2, but 3 I don\'t.

EDIT: here\'s an example on my Windows compute

7条回答
  •  隐瞒了意图╮
    2020-11-29 01:54

    Your shell (probably bash) is doing its own escaping, and that's confusing you. You can use an echo command to see what is being passed, or it's easy to write a custom program (commonly named "showargs" or similar):

    $ echo "s/\\\/\//"
    s/\\/\//
    $ echo "s/\\/\//"
    s/\/\//
    

    You can also use single quotes, which are treated differently in bash.

提交回复
热议问题