The shell command cmd may have whitespace and single and double quotes.
How to escape these quotes to correctly pass the command to a POSIX shell:
>dash -c 'cmd'
The other question pointed as a dup, asks about double quotes. One of the answers there is probably going to work - to split the command and use concatenated quotes. For example, if cmd were
cd "dir"; ls 'foobar'
then we would transform that into
>dash -c 'cd "dir"; ls '"'foobar'"
This is messy... is there no easier way?
Added: it seems like nobody understands me... I just want a general procedure, an algorithm, that takes on input, a string (to be completely precise, made out of printable ASCII characters from 0 to 127 in the ASCII table), and outputs, the second string. The requirement is that if the first string is executed like this
POSIX_shell>string1
the result is the same as
>POSIX_shell -c string2
Am I more clear now, please let me know.