Unfortunately this is all a bit vague and feels incomplete. Based on what you provided it won’t work and I don’t see enough information to know what you actually want or to point in the right direction
What’s the goal?
Can you walk me through what you’re hoping to do once you know the device state? Are you making call routing decisions, displaying it somewhere, etc.?
Can you give me more details?
What Asterisk version are you on?
Is SIP/109 a specific device you have, or just a placeholder?
How does this script fit into your dialplan? Can you show the dialplan?
This issue is a bash one, not an Asterisk one, although the first error may be the result of not marking up correctly for the forum.
david@dhcppc4:~$ echo “GET FULL VARIABLE DEVICE_STATE(SIP/109)”
bash: syntax error near unexpected token `('
david@dhcppc4:~$ echo "GET FULL VARIABLE DEVICE_STATE(SIP/109)"
GET FULL VARIABLE DEVICE_STATE(SIP/109)
david@dhcppc4:~$ echo "GET FULL VARIABLE ${DEVICE_STATE(SIP/109)}"
bash: GET FULL VARIABLE ${DEVICE_STATE(SIP/109)}: bad substitution
david@dhcppc4:~$ echo 'GET FULL VARIABLE ${DEVICE_STATE(SIP/109)}'
GET FULL VARIABLE ${DEVICE_STATE(SIP/109)}
david@dhcppc4:~$
The double quotes need to be the core ASCII ones, not the slanted ones that appeared in the forum. That is why the parentheses were rejected, but they would cause other errors, so I suspect they actually got introduced whilst submitting to the forum…
Although the synopsis documentation is totally confusing, there is a summary table that makes it clear that GET FULL VARIABLE is really GET EXPRESSION VALUE, so I think the $ are important, for which you need extensive backquoting, or single quotes, in the shell.