shellcheck
shellcheck copied to clipboard
Suggest "--" before filenames/operands for interaction with certain (many) utils
For new checks and feature suggestions
- [x] shellcheck.net (i.e. the latest commit) currently gives no useful warnings about this
- [x] I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
- Is "--" searchable?
Here's a snippet or screenshot that shows the problem:
#!/bin/bash
cat_with_lineno(){
cat -n "$@"
}
cat_with_lineno 1.txt -n.txt
Here's what shellcheck currently says:
$ shellcheck myscript
No issues detected!
Here's what I wanted or expected to see:
Warning: SC????: Use '--' before list of filenames to avoid parsing '-'-prefixed filenames as options.
cat -n "$@"
^---- Insert '--' here.
+1 from me. FYI it's called "Utility Syntax Guideline"
- http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02
How would it know what is a file name and what is a legal option? Consider this:
m=file2
n=file2
o=-8
gzip "$o" "$m"
gzip "$m" "$n"
How would shellcheck know that "--" should be after the first argument in the first one, and before it in the second?