Update: I just realized I'm terribly wrong, I don't know how to correct though.
For example, bash -c " echo "$S" "
and bash -c ' echo "$S" '
will get totally different output. but my current knowledge is still not enough to conclude correctly.
the title maybe sound a little confusing,
I mean, For example, as default bash -c ' echo " smth " '
if echo
requires a single quotes '
for itself usage, echo ' #!$smth '
then bash -c
will have to switch to Double quote "
instead, to differ echo
's single qutoe
so bash -c " echo ' #!$smth ' "
And there is no difference for bash -c
whatever single or double
quotes.
Do I understand right or please don't hesitate correct me.
Thanks.
bash -c ...
, there's two sets of shell command line processing, once in the outer shell before thebash -c ...
runs, and once inside it. The way we use different quotes in each determines the way expansions are made, or not made in each. Often you'd use single quotes on the outside, e.g. likefind . -type f -exec bash -c 'whatever "$1"' sh {} \;
, because with the single quotes, the outside shell doesn't touch the$1
, but the inner shell gets to expand it with what it was given (fromfind
here). Butbash -c "echo ' smth ' "
would be exactly the same either waybash -c
is wrong, I thought it didn't matter with single or double quotes forbash -c
itself , but actually it matters, it matters a lot. For example,bash -c " echo "$S" "
andbash -c ' echo "$S" '
will get totally different output. but my current knowledge is still not enough to conclude correctly.