Use printf instead of echo

The behaviour of "echo" is unspecified when the string contains 
backslashes.
This commit is contained in:
Jérémy Lecour 2019-03-10 00:34:33 +01:00
parent 0c6123bb54
commit 6568e66f73

View file

@ -137,18 +137,20 @@ End : $END_DATE
Message : $MESSAGE
END
)
echo "${BLOB}"
echo ""
printf "%s\n\n" "${BLOB}"
}
print_options() {
echo "********** Options ****************"
echo "MESSAGE: ${MESSAGE}"
echo "OPT_COMMIT: ${OPT_COMMIT}"
echo "OPT_DB: ${OPT_DB}"
echo "OPT_MAIL: ${OPT_MAIL}"
echo "DRY_RUN: ${DRY_RUN}"
echo "***********************************\n"
cat <<END
********** Options ****************
MESSAGE: ${MESSAGE}
OPT_COMMIT: ${OPT_COMMIT}
OPT_DB: ${OPT_DB}
OPT_MAIL: ${OPT_MAIL}
DRY_RUN: ${DRY_RUN}
***********************************
END
}
hook_commit() {
@ -181,7 +183,7 @@ hook_commit() {
done
if [ -n "${GIT_COMMITS}" ]; then
if [ "${VERBOSE}" = "1" ]; then
echo "\n\n********** Commits ****************\n${GIT_COMMITS}\n***********************************"
printf "\n\n********** Commits ****************\n%s\n***********************************\n" "${GIT_COMMITS}"
fi
if [ "${DRY_RUN}" != "1" ]; then
echo "${GIT_COMMITS}" >> "${LOGFILE}"
@ -195,7 +197,7 @@ hook_db() {
PG_QUERY="INSERT INTO evomaint(hostname,userid,ipaddress,begin_date,end_date,details) VALUES ('${HOSTNAME}','${USER}','${IP}','${BEGIN_DATE}',now(),'${SQL_DETAILS}')"
if [ "${VERBOSE}" = "1" ]; then
echo "\n\n********** DB query **************\n${PG_QUERY}\n***********************************"
printf "\n\n********** DB query **************\n%s\n***********************************\n" "${PG_QUERY}"
fi
if [ "${DRY_RUN}" != "1" ]; then
echo "${PG_QUERY}" | psql ${PGDB} ${PGTABLE} -h ${PGHOST}
@ -208,10 +210,10 @@ hook_mail() {
MAIL_CONTENT=$(sed -e "s/__TO__/${EVOMAINTMAIL}/ ; s/__HOSTNAME__/${HOSTNAME_TEXT}/ ; s/__USER__/${USER}/ ; s/__BEGIN_DATE__/${BEGIN_DATE}/ ; s/__END_DATE__/${END_DATE}/ ; s/__GIT_COMMITS__/${MAIL_GIT_COMMITS}/ ; s/__TEXTE__/${MAIL_TEXTE}/ ; s/__IP__/${IP}/ ; s/__FULLFROM__/${FULLFROM}/ ; s/__FROM__/${FROM}/ ; s/__URGENCYFROM__/${URGENCYFROM}/ ; s/__URGENCYTEL__/${URGENCYTEL}/" /usr/share/scripts/evomaintenance.tpl)
if [ "${VERBOSE}" = "1" ]; then
echo "\n\n********** Mail *******************\n${MAIL_CONTENT}\n***********************************"
printf "\n\n********** Mail *******************\n%s\n***********************************\n" "${MAIL_CONTENT}"
fi
if [ "${DRY_RUN}" != "1" ]; then
echo "${MAIL_CONTENT}" | ${SENDMAIL_BIN} -oi -t -f ${FROM}
echo "${MAIL_CONTENT}" | ${SENDMAIL_BIN} -oi -t -f "${FROM}"
fi
}
@ -365,7 +367,7 @@ fi
if [ -z "${MESSAGE}" ] && [ "${INTERACTIVE}" = "1" ]; then
# get input from stdin
echo "> Please, enter details about your maintenance"
printf "> Please, enter details about your maintenance:\n"
read -r MESSAGE
fi
@ -391,7 +393,7 @@ if [ "${INTERACTIVE}" = "1" ]; then
y="Y"; n="n"
answer=""
while true; do
echo "> Do you want to commit the changes? [${y}${n}] "
printf "> Do you want to commit the changes? [%s] " "${y}${n}"
read -r answer
case $answer in
[Yy] )
@ -428,7 +430,7 @@ if [ "${INTERACTIVE}" = "1" ]; then
fi
answer=""
while true; do
echo "> Do you want to insert your message into the database? [${y}${n}] "
printf "> Do you want to insert your message into the database? [%s] " "${y}${n}"
read -r answer
case $answer in
[Yy] )
@ -464,7 +466,7 @@ if [ "${INTERACTIVE}" = "1" ]; then
fi
answer=""
while true; do
echo "> Do you want to send an email to <${EVOMAINTMAIL}>? [${y}${n}e] "
printf "> Do you want to send an email to <%s>? [%s] " "${EVOMAINTMAIL}" "${y}${n}e"
read -r answer
case $answer in
[Yy] )
@ -475,11 +477,10 @@ if [ "${INTERACTIVE}" = "1" ]; then
break
;;
[Ee] )
echo "> To: [${EVOMAINTMAIL}] "
printf "> To: [%s] " "${EVOMAINTMAIL}"
read -r mail_recipient
if [ -n "${mail_recipient}" ]; then
EVOMAINTMAIL="${mail_recipient}"
echo "changed to ${EVOMAINTMAIL}"
fi
;;
"" )