From a0b025deac20da90ca292f7c713f9ffaf9a5fc07 Mon Sep 17 00:00:00 2001 From: Thibault Ayanides Date: Fri, 30 Oct 2020 14:56:27 +0100 Subject: [PATCH] Fix final printf command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The final printf bugs on non US system. A fix is to truncate the percentage to 2 decimals with bc and not with printf. modifié : bin/hardening.sh --- bin/hardening.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/hardening.sh b/bin/hardening.sh index b7be110..f843da6 100755 --- a/bin/hardening.sh +++ b/bin/hardening.sh @@ -273,7 +273,8 @@ if [ $BATCH_MODE ]; then BATCH_SUMMARY+="RUN_CHECKS:${TOTAL_TREATED_CHECKS:-0} " BATCH_SUMMARY+="TOTAL_CHECKS_AVAIL:${TOTAL_CHECKS:-0}" if [ $TOTAL_TREATED_CHECKS != 0 ]; then - BATCH_SUMMARY+=" CONFORMITY_PERCENTAGE:$(printf "%.2f" $( echo "($PASSED_CHECKS/$TOTAL_TREATED_CHECKS) * 100" | bc -l))" + CONFORMITY_PERCENTAGE=$(bc -l <<< "scale=2; ($PASSED_CHECKS/$TOTAL_TREATED_CHECKS) * 100") + BATCH_SUMMARY+=" CONFORMITY_PERCENTAGE:$(printf "%s" "$CONFORMITY_PERCENTAGE")" else BATCH_SUMMARY+=" CONFORMITY_PERCENTAGE:N.A" # No check runned, avoid division by 0 fi @@ -284,9 +285,12 @@ else printf "%30s %s\n" "Total Runned Checks :" "$TOTAL_TREATED_CHECKS" printf "%30s [ %7s ]\n" "Total Passed Checks :" "$PASSED_CHECKS/$TOTAL_TREATED_CHECKS" printf "%30s [ %7s ]\n" "Total Failed Checks :" "$FAILED_CHECKS/$TOTAL_TREATED_CHECKS" - printf "%30s %.2f %%\n" "Enabled Checks Percentage :" "$( echo "($TOTAL_TREATED_CHECKS/$TOTAL_CHECKS) * 100" | bc -l)" + + ENABLED_CHECKS_PERCENTAGE=$(bc -l <<< "scale=2; ($TOTAL_TREATED_CHECKS/$TOTAL_CHECKS) * 100") + CONFORMITY_PERCENTAGE=$(bc -l <<< "scale=2; ($PASSED_CHECKS/$TOTAL_TREATED_CHECKS) * 100") + printf "%30s %s %%\n" "Enabled Checks Percentage :" "$ENABLED_CHECKS_PERCENTAGE" if [ $TOTAL_TREATED_CHECKS != 0 ]; then - printf "%30s %.2f %%\n" "Conformity Percentage :" "$( echo "($PASSED_CHECKS/$TOTAL_TREATED_CHECKS) * 100" | bc -l)" + printf "%30s %s %%\n" "Conformity Percentage :" "$CONFORMITY_PERCENTAGE" else printf "%30s %s %%\n" "Conformity Percentage :" "N.A" # No check runned, avoid division by 0 fi