This seems like such a simple fix that I'm a bit embarrassed to ask, but I'm having trouble getting a variable to resolve in a shell command:
read -r -p "SIP Peer name (e.g. ATAx1): " peer
status=`sudo asterisk -rx 'sip show peer $peer' | grep -i "status"`
I tried surrounding $peer with quotes like "$peer" as well, but the result is the same:
SIP Peer name (e.g. ATAx1): ATAx1
SIP Peer status for ATAx1:
Press ENTER to return:
For kicks, I tried hardcoding it in like so:
status=`sudo asterisk -rx 'sip show peer ATAx1' | grep -i "status"`
And voila!
SIP Peer name (e.g. ATAx1): ATAx1
SIP Peer status for ATAx1: Status : UNKNOWN
It works! Yes, the status is supposed to be "Unknown". But more importantly, why is the variable $peer not working here?
Sometimes I copy and paste syntax and forget to match the variable generated by the read command with that actually used in the shell command, but that is not the case here.
Are you not allowed to use variables in these statements? Or more likely, is some special syntax required? I can't single quote obviously, and I tried double quoting. Is there a syntax error here causing the variable to not get used in the command?