Skip to content

Commit

Permalink
utils: Prefer printf over echo -e.
Browse files Browse the repository at this point in the history
On Ubuntu, `/bin/sh` defaults to `dash` whose built-in `echo` command
does not support the `-e` flag. `printf`, on the other hand, supports
backslash escapes by default so we use that instead.

In passing, also clean up some messy ANSI escape codes.
  • Loading branch information
seanbright authored and linuxmaniac committed Dec 12, 2023
1 parent 14e763f commit 8d3d53f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/kamailio/obs/kamailio.init
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ check_kamailio_config ()
retcode=$?
if [ "$retcode" != '0' ]; then
echo "Not starting $PROG: invalid configuration file!"
echo -e "\n$out\n"
printf "\n$out\n\n"
exit 1
fi
}
Expand Down
2 changes: 1 addition & 1 deletion utils/kamctl/kamctl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fi
if [ -f "$MYLIBDIR/kamctl.base" ]; then
. "$MYLIBDIR/kamctl.base"
else
echo -e "Cannot load core functions '$MYLIBDIR/kamctl.base' - exiting ...\n"
printf "Cannot load core functions '%s' - exiting ...\n\n" "$MYLIBDIR/kamctl.base"
exit -1
fi

Expand Down
10 changes: 5 additions & 5 deletions utils/kamctl/kamctl.base
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_acc"
mdbg() {
if [ "0$VERBOSE" -ne 0 ] ; then
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e "\033[1m$1\033[0m"
printf "\033[1m%s\033[0m\n" "$1"
else
echo "$1"
fi
Expand All @@ -608,31 +608,31 @@ mdbg() {

mwarn() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;32m'"\033[1mWARNING: $1\033[0m"
printf "\033[32;1mWARNING: %s\033[0m\n" "$1"
else
echo "** WARNING: $1"
fi
}

minfo() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;33m'"\033[1mINFO: $1\033[0m"
printf "\033[33;1mINFO: %s\033[0m\n" "$1"
else
echo "** INFO: $1"
fi
}

mecho() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e "\033[1m$1\033[0m"
printf "\033[1m%s\033[0m\n" "$1"
else
echo "$1"
fi
}

merr() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;31m'"\033[1mERROR: $1\033[0m"
printf "\033[31;1mERROR: %s\033[0m\n" "$1"
else
echo "** ERROR: $1"
fi
Expand Down
6 changes: 3 additions & 3 deletions utils/kamctl/kamdbctl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fi
if [ -f "$MYLIBDIR/kamdbctl.base" ]; then
. "$MYLIBDIR/kamdbctl.base"
else
echo -e "Cannot load core functions '$MYLIBDIR/kamdbctl.base' - exiting ...\n"
printf "Cannot load core functions '%s' - exiting ...\n\n" "$MYLIBDIR/kamdbctl.base"
exit -1
fi

Expand Down Expand Up @@ -377,7 +377,7 @@ case $1 in
# create new database structures

# confirm dropping of database
echo -e "This will drop your current database.\nIt is recommended to first backup your database.\n"
printf "This will drop your current database.\nIt is recommended to first backup your database.\n\n"
get_answer ask "Continue with drop? (y/n): "
if [ "$ANSWER" != "y" ]; then
exit 1
Expand All @@ -396,7 +396,7 @@ case $1 in
# create new database structures

# confirm dropping of database
echo -e "This will drop your current database and create a new one.\nIt is recommended to first backup your database.\n"
printf "This will drop your current database and create a new one.\nIt is recommended to first backup your database.\n\n"
get_answer ask "Continue with reinit? (y/n): "
if [ "$ANSWER" != "y" ]; then
exit 1
Expand Down
10 changes: 5 additions & 5 deletions utils/kamctl/kamdbctl.base
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ credentials()
mdbg() {
if [ "0$VERBOSE" -ne 0 ] ; then
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e "\033[1m$1\033[0m"
printf "\033[1m%s\033[0m\n" "$1"
else
echo "$1"
fi
Expand All @@ -163,31 +163,31 @@ mdbg() {

mwarn() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;32m'"\033[1mWARNING: $1\033[0m"
printf "\033[32;1mWARNING: %s\033[0m\n" "$1"
else
echo "** WARNING: $1"
fi
}

minfo() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;33m'"\033[1mINFO: $1\033[0m"
printf "\033[33;1mINFO: %s\033[0m\n" "$1"
else
echo "** INFO: $1"
fi
}

mecho() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e "\033[1m$1\033[0m"
printf "\033[1m%s\033[0m\n" "$1"
else
echo "$1"
fi
}

merr() {
if [ -t 1 -a -z "$NOHLPRINT" ] ; then
echo -e '\E[37;31m'"\033[1mERROR: $1\033[0m"
printf "\033[31;1mERROR: %s\033[0m\n" "$1"
else
echo "** ERROR: $1"
fi
Expand Down

0 comments on commit 8d3d53f

Please sign in to comment.