Thursday 26 October 2017

linux - Print single quotes in shell script using option -c

You can't nest single quotes in bash, so the line is
interpreted as


/bin/bash -l -c 'echo
"'John'"'
|......| ---------- single quoted
|....| ----- not
quoted
|.| ---
quoted

So, properly escape the
single quotes:


/bin/bash -c 'echo
"'\''John'\''"'

or, if the string
in single quotes is really simple,


/bin/bash
-c 'echo "'\'John\''"'

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...