有人知道包含 '|'
或 '&'
的字符串的 wordexp()
行为吗?
我使用 wordexp(str, &res, WRDE_UNDEF)
,但使用包含 '|'
或 '&'
的所有字符串 wordexp()
返回 WRDE_BADCHAR
。我希望 wordexp()
不会报告此情况。
例如我希望 wordexp("a & b", &res, WRDE_UNDEF)
返回带有 3 个字符串 "a""&""b"
的 wordexp_t
.
最佳答案
非法字符( newline
或 |
、 &
、 ;
、 <
、 >
、 (
、 )
、 {
, }
) 需要转义。这是通过在它们前面加上 \
前缀来完成的。 .
逐字记录 man wordexp
:
The string argument
Since the expansion is the same as the expansion by the shell (see sh(1)) of the parameters to a command, the string s must not contain characters that would be illegal in shell command parameters. In particular, there must not be any unescaped newline or |, &, ;, <, >, (, ), {, } characters outside a command substitution or parameter substitution context.
关于c - Wordexp 与 & 的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18259188/