You need to use back ticks
or better the recommended new-style command substitution syntax
While both forms are supported, there are limitations to script embedding in the former.
A quote from The Open Group Base Specifications Issue 7, 2018 edition:
The "$()" form of command substitution solves a problem of inconsistent behavior when using backquotes. For example:
echo '\$x' \$x
echo `echo '\$x'` $x
echo $(echo '\$x') \$x
Additionally, the backquoted syntax has historical restrictions on the contents of the embedded command. While the newer "$()" form can process any kind of valid embedded script, the backquoted form cannot handle some valid scripts that include backquotes. For example, these otherwise valid embedded scripts do not work in the left column, but do work on the right:
echo ` echo $(
cat <<\eof cat <<\eof
a here-doc with ` a here-doc with )
... end of quote.