shell - how to escape quotes in command argument to sh -c? -


this question has answer here:

the shell command cmd may have whitespace , single , double quotes.

how escape these quotes correctly pass command posix shell:

>dash -c 'cmd'

the other question pointed dup, asks double quotes. 1 of answers there going work - split command , use concatenated quotes. example, if cmd were

cd "dir"; ls 'foobar' 

then transform into

>dash -c 'cd "dir"; ls '"'foobar'" 

this messy... there no easier way?

added: seems nobody understands me... want general procedure, algorithm, takes on input, string (to precise, made out of printable ascii characters 0 127 in ascii table), , outputs, second string. requirement if first string executed this

posix_shell>string1 

the result same as

>posix_shell -c string2 

am more clear now, please let me know.

first of all, try avoid messy things mentioned. if have to, keep simple, double quotes inside single quote have no problem. single quote inside double quotes should not problem.

#example: echo '"these double quoted"' echo "'these single quoted'" 

third (messy , avoid if possible), single quote want inside single quote, has escaped using multiple quotes.

echo ''"'"'these single quoted, messy'"'"'' 

fourth, double quote inside double quote should escaped using backslash \

echo "\"these double quoted\"" 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -