#!/usr/bin/env bash
cat "${1--}" | lolcat
#lolcat < "${1--}" #this would fail, when no argument is supplied
Line 3:
cat "${1--}" | lolcat
^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
When cat's argument expands to a dash ("-"), cat will use the stdin instead of the file. In the snippet this means that when no argument is supplied, the stdin is fed to lolcat.
With lolcat< "${1--}", bash raises the error "No such file or directory" when $1 is unset.
Not sure how shellcheck should handle this. Suggestion: perhaps don't show this error only when a variable is referenced using ${x--}? So if the programmer wants to use stdin instead of a file, the variable $x has to be unset. This will add one extra line to translate "-" to an unset variable.
Not a useful use of cat. When lolcat's argument expands to a dash, lolcat will also use stdin instead of the file.
#!/usr/bin/env bash
# Both lines below work
lolcat "${1--}"
lolcat < "${1-/dev/stdin}" # If you want to use redirection
Most helpful comment
Not a useful use of cat. When lolcat's argument expands to a dash,
lolcatwill also use stdin instead of the file.