So I have a Bash script which looks like this:
#!/bin/bash
extentemplate="
exten => `$prevchannel`,n,Queue(`$prevchannelname`)\
exten => `$prevchannel`,n,Hangup()\
\
;`$channelname`\
exten => `$channel`,1,Answer()\
exten => `$channel`,n,ResetCDR()\
exten => `$channel`,n,Set(CDR(accountcode)=`$accountcode`)\
exten => `$channel`,n,Set(CDR(userfield)=inbound)\
exten => `$channel`,n,Set(MONITOR_FILENAME=`$channelname`_\${UNIQUEID})\
exten => `$channel`,n,Set(CALLERID(name)=`$channelname`)\
exten => `$channel`,n,Queue(`$channelname`)\
exten => `$channel`,n,Hangup()\
"
FILE="/etc/asterisk/extensions.pap.confTEST"
args=("$@")
operation=("${args[0]}")
channel=("${args[1]}")
accountcode=("${args[2]}")
channelname=("${args[3]}")
music=("${args[6]}")
prevchannel=("${args[4]}")
prevchannelname=("${args[5]}")
if [ $operation = "add" ] ; then
sed "s/exten => `$prevchannel`,n,Queue(`$prevchannelname`)/`$extentemplate`/" $FILE
fi
According to the answers I've seen so far this should be able to get substituted correctly however apparently I haven't escaped something or other correctly.
My args don't contain any special characters.
Does anyone know why this is failing with the "unterminated `s' command" error?
set -x
in the script and look at what is actually being sent to sed (you can useset +x
to stop printing commands).extentemplate=
starts with a newline. Are all these backticks really single quotes?