$ cat my_test.txt
My test for sed starts here :)
$ sed -i '1s/^/\hi.../' my_test.txt
$ cat my_test.txt
hi...My test for sed starts here :)
$ sed -i '1s/^/\x11/' my_test.txt
$ cat my_test.txt
hi...My test for sed starts here :)
$ sed -i '1s/^/\x11.../' my_test.txt
$ cat my_test.txt
...hi...My test for sed starts here :)
$ sed -i '1s/^/\x11...x11/' my_test.txt
$ cat my_test.txt
...x11...hi...My test for sed starts here :)
比较strace输出,这里分别为
read(3, "My test for sed starts here :)\n", 32768) = 31
write(4, "hi...My test for sed starts here"..., 36) = 36
read(3, "hi...My test for sed starts here"..., 32768) = 36
write(4, "\21hi...My test for sed starts her"..., 37) = 37
read(3, "\21hi...My test for sed starts her"..., 32768) = 37
write(4, "\21...\21hi...My test for sed starts"..., 41) = 41
read(3, "\21...\21hi...My test for sed starts"..., 32768) = 41
write(4, "\21...x11\21...\21hi...My test for sed"..., 48) = 48
答案 0 :(得分:1)
\hi
前面的反斜杠是不必要的,但没有损坏。
\x11
前面的反斜杠表示字符为十六进制0x11或八进制021或 Control-Q ,如读/写跟踪所示。这不是打印字符,因此您看不到cat
(您必须使用cat -v
才能看到它)。
翻译由GNU sed
完成,如Escapes部分所述 - 在这种情况下,它不是shell(Bash)正在进行字符映射。