In bash, when I run the following command:
sh -c \"command\"
is there created a subshell and then the command
I think that with examples it's possible to understand the situation
(in my case sh is a symbolic link to /bin/dash).
I did this tests for sh:
echo $$ ; sh -c 'echo $$ ; sh -c '"'"'echo $$'"'"' '
16102
7569
7570
Three different PID, three different shell. (If there are different shells, there is not a subshell spawn).
In a similar way for BASH
echo $$ $BASHPID, $BASH_SUBSHELL ; bash -c 'echo $$ $BASHPID $BASH_SUBSHELL ; bash -c '"'"'echo $$ $BASHPID $BASH_SUBSHELL '"'"' '
16102 16102, 0
10337 10337 0
10338 10338 0
Three different $BASHPID no different $BASH_SUBSHELL (see note below for differences between $$ and $BASHPID).
If we were in a subshell that do not require to be reinitialized, then $$ and $BASHPID should be different.
In the same way $BASH_SUBSHELL is not incremented, it is always 0.
So 2 clues to say again that no new subshell are spawned, we have only new shells.
From man bash (4.2.45(1)-release) I report some pertinent parts about when a subshell is spawned:
Each command in a pipeline is executed as a separate process (i.e., in a subshell).
If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0.
Commands separated by a ; are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed. ...
( list ) list is executed in a subshell environment
{ list; } list is simply executed in the current shell environment.
A coprocess is a shell command preceded by the coproc reserved word. A coprocess is executed asynchronously in a subshell...
$ Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the current shell, not the subshell.
Notes:
BASHPID Expands to the process ID of the current bash process. This differs from $$
under certain circumstances, such as subshells that do not require bash to be
re-initialized. BASH_SUBSHELL Incremented by one each time a subshell or subshell environment is spawned. The initial value is 0.
For the differences between the use of single quote '' an double quote "" you can see this question. Let we remember only that if you write the commands within double quote"" the variables will be evaluated via parameter expansion from the original shell, if extquote is enabled as it is by default from shopt.(cfr. 4.3.2 The shopt builtin in the Bash Reference Manual)
*extquote*If set, $'string' and $"string" quoting is performed within ${parameter} expansions enclosed in double quotes. This option is enabled by default.
For further references you may find useful e.g.
man bash.Shell Expansions of the bash manual.