Consider file main.sh as
#!/usr/bin/bash
echo "Main PID is $$"
CMD="./helper.sh"
echo $($CMD)
consider helper.sh as
#!/usr/bin/bash
echo "PPID in helper script is $$"
echo "Bash pid is $BASHPID"
When I run ./main.sh
the output is
Main PID is 867
PPID in helper script is 868 Bash pid is 868
Now my query is that the command substitution used to run helper.sh
from main.sh
shoud've spawned a subshell which has its own PID which'll be returned by $BASHPID
but $$
must've returned the parent PID i.e. the pid of shell in which main.sh
is running as is indicated by this answer.
So why is it not the case and parent pid is the same as current shell pid in helper.sh
?