Reputation: 4107
This exact code was working in another script. I copied the function over and now it keeps giving the unterminated 's' command error.
sed "
s@<%BRANCH-NAME%>@${_loc_name}@g
s@<%BRANCH-ADDR%>@${_loc_strt}@g
s@<%BRANCH-CTY%>@${_loc_city}@g
s@<%CUST-NAME%>@${_pat_name}@g
s@<%CUST-ADDR%>@${_pat_addr}@
s@<%CUST-CTY%>@${_pat_city}@
s@<%BARCODE%>@${_barcode}@g
s@<%DATE%>@${_date}@
s@<%TITLE%>@${_title}@
s@<%AUTHOR%>@${_auth}@
s@<%PRICE%>@${_price}@" "$_template"
In response to requests for possible values:
These are huge files and this function is in a for loop. I use it to format forms for mailing. More info here: BASH: importing data from flat file into template
So this function worked for certain directories but I've hit a snag with this recent one.
I grepped for slash characters on the advice of kev below ...none found except '/'. Possibly 'silent' newlines.
find ./ -name "mail.TMP" -type f -exec grep -E '\n' {} \;
possible values would be things like:
${pat_name}
Hermann Hesse c/o His Mother
${loc_name}
Pandora SR home c/o Harmony City Hall
So ...maybe it's a quoting issue?
Upvotes: 1
Views: 1575
Reputation: 161954
$ _loc_name=$'xxx\nyyy'
$ echo '<%BRANCH-NAME%>' | sed "s@<%BRANCH-NAME%>@${_loc_name}@g"
sed: -e expression #1, char 21: unterminated `s' command
Does any $var
contain newline
? Please echo
them all to check.
$ echo "$_loc_name"
xxx
yyy
Upvotes: 1