A disk check fails with `[: 93%: integer expression expected`
BeginnerTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer
Likely causes → The value contains non-digits: the % from df, a trailing \r, whitespace, a decimal (93.5), or an empty string.
Diagnose → printf '%q\n' "$pct" reveals hidden characters like $'93%\r'.
Fix → Clean the value before comparing:
pct=$(df -P / | awk 'NR == 2 {gsub(/%/, "", $5); print $5}')
[[ $pct =~ ^[0-9]+$ ]] || die "unexpected df output: $pct"
(( pct >= 90 )) && alert
Prevent → Validate numeric input with a regex before arithmetic; for decimals compare with awk.
More on Troubleshooting: quoting, expansion and tool-input bugs
`bash: [: too many arguments`Beginner`bash: [: =: unary operator expected`Beginner`rm $file` fails with `rm: cannot remove 'monthly': No such file or directory` and `rm: cannot remove 'report.csv'`.BeginnerA cleanup script logs `cp: cannot stat '/var/log/app/*.log': No such file or directory` on quiet days.Beginner`echo "start" > $logfile` fails with `bash: $logfile: ambiguous redirect`Intermediate`hosts[${#hosts[@]}-1]` style code fails with `bash: hosts: bad array subscript`.Intermediate