- 论坛徽章:
- 0
|
本帖最后由 没本 于 2010-06-23 01:58 编辑
你显然还没把sh/bash的文法和C文法区分清楚。你的命令行是sh/bash文法,argv拿到的就是按C文法处理了。在sh/bash文法里面,\a是无效的,所以\被忽略了。参见:
http://www.gnu.org/software/bash ... ml#Escape-Character
- 3.1.2.1 Escape Character
- A non-quoted backslash ‘\’ is the Bash 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 itself is not quoted, the \newline is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).
复制代码 另外bash还提供了一个语法(注意要用$'带反斜杠字符串'):
http://www.gnu.org/software/bash ... #ANSI_002dC-Quoting
- 3.1.2.4 ANSI-C Quoting
- Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:
- \a
- alert (bell)
- \b
- backspace
- \e
- \E
- an escape character (not ANSI C)
- \f
- form feed
- \n
- newline
- \r
- carriage return
- \t
- horizontal tab
- \v
- vertical tab
- \\
- backslash
- \'
- single quote
- \"
- double 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.
复制代码 |
|