shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

Suggest "--" before filenames/operands for interaction with certain (many) utils

Open Artoria2e5 opened this issue 9 years ago • 3 comments

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.

Artoria2e5 avatar Nov 23 '16 23:11 Artoria2e5

+1 from me. FYI it's called "Utility Syntax Guideline"

  • http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02

nodakai avatar Feb 04 '17 04:02 nodakai

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?

arth1 avatar Apr 01 '17 08:04 arth1