Friday, 6 February 2015

Re: [gccsdk] exec() possibly a problem

Hi Ron,

> My useage here is in fact wrong, it appears that command and args are
> wrapped in single quotes for a subshell. (Also done in a shellscript)

No, that's too simplistic. Unix shells like dash follow
http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
in their processing of the backslash escape, and single and double
quotes.

> $ $PATH/sh -c 'printf "hello...\\n"'
> hello...
> $
> all good
> Simplifies things, now just the \\n being needed across the new
> process.

I've only skimmed this thread to date, but be aware that there are three
processes parsing that command above. The dash shell that's printed the
`$ ' prompt. The sh you explicitly start. And the printf that's either
a built-in to the shell or a separate executable that's processing the
argv[] its main has been passed. All three of them are happy to
interpret a backslash-escape in some circumstances.

As an example, double quotes, which allow more interpolating, aren't
necessary above. Another layer of single quotes can be used, with them
mechanically being escaped, e.g.

$ sh -c 'printf '\''hello...\n'\'
hello...
$

Cheers, Ralph.

_______________________________________________
GCCSDK mailing list gcc@gccsdk.riscos.info
Bugzilla: http://www.riscos.info/bugzilla/index.cgi
List Info: http://www.riscos.info/mailman/listinfo/gcc
Main Page: http://www.riscos.info/index.php/GCCSDK

No comments:

Post a Comment