diff options
author | Stéphane Lesimple <speed47_github@speed47.net> | 2018-01-18 11:00:40 +0100 |
---|---|---|
committer | Stéphane Lesimple <speed47_github@speed47.net> | 2018-01-20 12:23:55 +0100 |
commit | 3be5e904818a440c3c63261eb16ee095e8e9a996 (patch) | |
tree | 594e2929073bd6f9528b80911816d08d97c4510f | |
parent | 995620a6824d3f1711cadd8c17d3f6d8d266dc7c (diff) | |
download | spectre-meltdown-checker-3be5e904818a440c3c63261eb16ee095e8e9a996.tar.lz spectre-meltdown-checker-3be5e904818a440c3c63261eb16ee095e8e9a996.tar.xz spectre-meltdown-checker-3be5e904818a440c3c63261eb16ee095e8e9a996.zip |
be smarter to find a usable echo command
-rwxr-xr-x | spectre-meltdown-checker.sh | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/spectre-meltdown-checker.sh b/spectre-meltdown-checker.sh index bc2f1c2..32f7442 100755 --- a/spectre-meltdown-checker.sh +++ b/spectre-meltdown-checker.sh @@ -97,17 +97,31 @@ global_critical=0 global_unknown=0 nrpe_vuln="" +echo_cmd='' __echo() { opt="$1" shift _msg="$@" + + if [ -z "$echo_cmd" ]; then + # find a sane `echo` command + # we'll try to avoid using shell builtins that might not take options + if which echo >/dev/null 2>&1; then + echo_cmd=`which echo` + else + [ -x /bin/echo ] && echo_cmd=/bin/echo + [ -x /system/bin/echo ] && echo_cmd=/system/bin/echo + fi + # still empty ? fallback to builtin + [ -z "$echo_cmd" ] && echo_cmd=echo + fi + if [ "$opt_no_color" = 1 ] ; then # strip ANSI color codes - _msg=$(/bin/echo -e "$_msg" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g") + _msg=$($echo_cmd -e "$_msg" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g") fi - # explicitly call /bin/echo to avoid shell builtins that might not take options - /bin/echo $opt -e "$_msg" + $echo_cmd $opt -e "$_msg" } _echo() |