If I understood well, not realy.
Your question boil down to : am I running
foobar from "main" shell or
echo $(foobar) (command substitution) ?
foobar may test the following
tty (am I under a tty ? )
$SHLVL (how many stack of shell ? )
Depending on your need, you may store and compare
SHLVL var, this supposed you (your shell) are the one that run the command.
I put quote arroud main, because there is no such thing as main shell, you have loggin shell (with a tty), shell forked from cron, daemons (mails, apache), but no "main" shell.
as pointed SHLVL might be tricky to use
archemar@home> cat t2.sh
echo "$SHLVL" $1
archemar@home> . ./t2.sh $SHLVL
archemar@home> ./t2.sh $SHLVL
archemar@home> ./t2.sh $(./t2.sh)