Question

Does anybody knows wordexp() behaviour with strings, which contained '|' or '&'.

I use wordexp(str, &res, WRDE_UNDEF), but with all strings, which contained '|' or '&' wordexp() returns WRDE_BADCHAR. I want that wordexp() doesn't report this.

E.g. I want that wordexp("a & b", &res, WRDE_UNDEF) returns wordexp_t with 3 strings "a" "&" "b".

Was it helpful?

Solution

Illegal characters (newline or |, &, ;, <, >, (, ), {, }) need to be escaped. This is done by prefixing them with \.

Verbatim from 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top