That generally works; e.g. try
P=$(echo $PATH)
when in doubt - use the ${PATH} braces and/or escaped "'s - as to control a single argument with spaces or something which is expanded; and has its spaces seen as separators between arguments. (Which is by the way not needed in your example if we assume that we have no filenames and what not with spaces in them).
As a larger example - consider:
#!/bin/sh
dev=$(echo /dev/null)
if [ $(cat $dev | wc -l) = "0" ]; then
echo Fine
exit 0
else
echo Now that is a surprize
fi
exit 1
which when ran gives us
beeb-2:~ dirkx$ sh xx.sh
Fine
or more elaborate:
beeb-2:~ dirkx$ sh -x xx.sh
++ echo /dev/null
+ dev=/dev/null
++ cat /dev/null
++ wc -l
+ '[' 0 = 0 ']'
+ echo Fine
Fine
+ exit 0
so that should help you find the issue. You sure there is not some space or transposition ?