`bash: [: too many arguments`
BeginnerTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer
Likely causes → An unquoted variable inside [ ] contains spaces or glob characters and expands to several words: [ $status = "active" ] with status="not found". Also happens with [ -f $file ] when $file matches multiple files via globbing.
Diagnose → bash -x shows the expanded test, e.g. + '[' not found = active ']'.
Fix → Quote: [ "$status" = active ], or use [[ $status == active ]].
Prevent → Quote every expansion; ShellCheck SC2086.
More on Troubleshooting: quoting, expansion and tool-input bugs
`bash: [: =: unary operator expected`BeginnerA disk check fails with `[: 93%: integer expression 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