2 days ago
- Useless Use of Cat Award: Using cat on a single file to pipe it to another command is wasteful and unnecessary; use input redirection or pass the file as an argument instead.
- Useless Use of echo: Using echo in backticks to pass variables to commands is often redundant; directly use the variable or simpler constructs unless specific whitespace flattening is needed.
- Useless Use of ls in loops: Using ls * in for loops is inefficient as glob expansion already handles file listing; use glob patterns directly and avoid backticks for safer and cleaner code.
- Useless Use of wc -l with grep: Using grep with wc -l to count lines is often unnecessary; use grep -c . for counting or grep -q to check for output, or rely on exit codes.
- Danger of kill -9: Avoid using kill -9 as it forcefully terminates processes without allowing cleanup; start with signals like 15, 2, or 1 for graceful shutdown and only use -9 as a last resort.
- Useless Use of Backticks: Overusing backticks can lead to issues with command-line length limits (ARG_MAX) and unexpected behavior with file names containing spaces or newlines; consider while read loops or xargs for safer alternatives.
- Alternatives to Complex Commands: Prefer simpler tools like cut over awk for straightforward field extraction, and use built-in shell features for tasks like case conversion or character removal, avoiding unnecessary complexity.
- Scripting Best Practices: Use if statements to check command exit codes directly rather than checking $?, and avoid redundant constructs like test with unnecessary regular expressions or heavy tools for simple tasks.