原帖由 ailms 于 2007-12-13 14:51 发表
[root@mail ~]# cat a
='
'>
\n
\r
[root@mail ~]# sed "s/'>/\\\'>/" a
='
\'>
\n
\r
[root@mail ~]#
原帖由 ailms 于 2007-12-14 14:57 发表
单纯 \\'>和\\\'> 并没有区别,但你要放到整个 sed 的表达式,和前面的 " ' " 一起看啊,
加个 \ 就是为了去掉 ' 字符的 quoting 含义,变成一个普通字符
[root@mail ~]# cat a
='
'>
\n
\r
[root@mail ~]# sed "s/'>/\\\'>/" a
='
\'>
\n
\r
[root@mail ~]#
QUOTING
Quoting is used to remove the special meaning of certain characters or
words to the shell. Quoting can be used to disable special treatment
for special characters, to prevent reserved words from being recog-
nized as such, and to prevent parameter expansion.
Each of the metacharacters listed above under DEFINITIONS has special
meaning to the shell and must be quoted if it is to represent itself.
When the command history expansion facilities are being used, the his-
tory expansion character, usually !, must be quoted to prevent history
expansion.
There are three quoting mechanisms: the escape character, single
quotes, and double quotes.
A non-quoted backslash (\) is the escape character. It preserves the
literal value of the next character that follows, with the exception
of <newline>. If a \<newline> pair appears, and the backslash is not
itself quoted, the \<newline> is treated as a line continuation (that
is, it is removed from the input stream and effectively ignored).
Enclosing characters in single quotes preserves the literal value of
each character within the quotes. A single quote may not occur
between single quotes, even when preceded by a backslash.
Enclosing characters in double quotes preserves the literal value of
all characters within the quotes, with the exception of $, ‘, and \.
The characters $ and ‘ retain their special meaning within double
quotes.The backslash retains its special meaning only when followed
by one of the following characters: $, ‘, ", \, or <newline>. A dou-
ble quote may be quoted within double quotes by preceding it with a
backslash. When command history is being used, the double quote may
not be used to quote the history expansion character.
The special parameters * and @ have special meaning when in double
quotes (see PARAMETERS below).
Words of the form $’string’ are treated specially. The word expands
to string, with backslash-escaped characters replaced as specifed by
the ANSI C standard. Backslash escape sequences, if present, are
decoded as follows:
\a alert (bell)
\b backspace
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\’ single quote
\nnn the eight-bit character whose value is the octal value
nnn (one to three digits)
\xHH the eight-bit character whose value is the hexadecimal
value HH (one or two hex digits)
\cx a control-x character
The expanded result is single-quoted, as if the dollar sign had not
been present.
A double-quoted string preceded by a dollar sign ($) will cause the
string to be translated according to the current locale. If the cur-
rent locale is C or POSIX, the dollar sign is ignored. If the string
is translated and replaced, the replacement is double-quoted.
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |