A cleanup script logs `cp: cannot stat '/var/log/app/*.log': No such file or directory` on quiet days.
BeginnerTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer
Likely causes → No file matched the glob, so Bash passed the pattern literally to cp. A for f in /var/log/app/*.log loop has the same issue and runs once with the literal pattern.
Diagnose → ls /var/log/app/ on that day; bash -x shows the literal *.
Fix →
shopt -s nullglob
files=(/var/log/app/*.log)
(( ${#files[@]} )) || { echo "nothing to copy"; exit 0; }
cp -- "${files[@]}" /backup/
Prevent → Use nullglob (or [[ -e $f ]] || continue inside loops) whenever a glob may match nothing.
More on Troubleshooting: quoting, expansion and tool-input bugs
`bash: [: too many arguments`Beginner`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'`.Beginner`echo "start" > $logfile` fails with `bash: $logfile: ambiguous redirect`Intermediate`hosts[${#hosts[@]}-1]` style code fails with `bash: hosts: bad array subscript`.Intermediate