Interview Prep/Shell Scripting/Troubleshooting: tools, portability, permissions and environment

A load check fails with `bash: ((: 4.75: syntax error: invalid arithmetic operator (error token is ".75")`.

BeginnerTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer

Likely causes → Bash arithmetic is integer-only. /proc/loadavg, bc output and many metrics are decimals, which (( )) and [ -gt ] cannot handle.

Diagnose → cat /proc/loadavg shows values like 4.75 3.10 2.02.

Fix → Compare in awk, which uses floating point, and return the result as an exit status:

read -r load1 _ < /proc/loadavg
cores=$(nproc)
if awk -v l="$load1" -v c="$cores" 'BEGIN { exit !(l > c * 1.5) }'; then
  alert WARNING "load $load1 on $cores cores"
fi

Prevent → Do decimal maths in awk, and keep integers in Bash (percentages without %, bytes, seconds).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: tools, portability, permissions and environment