Skip to content

Commit 024c7a1

Browse files
authored
Update addMessage.sh: fix replacing newlines
1 parent 3daca6e commit 024c7a1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

scripts/addMessage.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,20 @@ COUNT=0
3636
TAB="$(echo -e "\t")"
3737

3838
# Convert newlines to HTML breaks.
39-
MESSAGE="${MESSAGE//\\n/<br>}"
39+
MESSAGE="$( echo -n "${MESSAGE}" |
40+
awk 'BEGIN { l=0; } { if (++l > 1) printf("<br>"); printf("%s", $0); }' )"
41+
MESSAGE="${MESSAGE// /&nbsp;&nbsp;}"
42+
4043
# Messages may have "/" in them so we can't use that to search in sed,
4144
# so use "%" instead, but because it could be in a message (although unlikely),
4245
# convert all "%" to the ASCII code.
43-
MESSAGE="${MESSAGE//%/&#37;}"
46+
# The pound sign in escaped only to make gvim look nicer.
47+
MESSAGE="${MESSAGE//%/&\#37;}"
4448

4549
# If ${MESSAGE} contains "*" it hoses up the grep and sed regular expression, so escape it.
4650
ESCAPED_MESSAGE="${MESSAGE//\*/\\*}"
4751

52+
4853
if [[ -f ${ALLSKY_MESSAGES} ]] && M="$(grep "${TAB}${ESCAPED_MESSAGE}$" "${ALLSKY_MESSAGES}")" ; then
4954
# tail -1 in case file is corrupt and has more than one line we want.
5055
PRIOR_COUNT=$(echo -e "${M}" | cut -f3 -d"${TAB}" | tail -1)

0 commit comments

Comments
 (0)