shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2038 seems to be triggered even when suggested form is used

Open srcshelton opened this issue 9 months ago • 0 comments

Version: v0.10.0-68-gd3001f3

Result from shellcheck:

In /mnt/generate-Kconfig.sh line 94:
  find "${repodir}/" \
  ^-- SC2038 (warning): Use 'find .. -print0 | xargs -0 ..' or 'find .. -exec .. +' to allow non-alphanumeric filenames.

Code:

 93             for dir in $( # <- Syntax
 94                     find "${repodir}/" \
 95                             -mindepth 3 \
 96                             -maxdepth 3 \
 97                             -name '*.ebuild' \
 98                             -type f \
 99                             -exec \
100                                 grep -Fl -- 'CONFIG_CHECK' {} + |
101                         xargs -rn 1 dirname |
102                         sort |
103                         uniq 
104                 )
105             do
    ...

The code already appears to be expressed in the second form suggested: find .. -exec .. + - I suspect that the line-continuation characters are throwing off this check?

(Admittedly, any update to the invocation of the find command above to correctly handle less-usual filenames would then be broken again by the for-loop, but that's not what SC2038 is talking about - really, the advice should be to refactor the code to something along the lines of:

  while read -r dir; do
    …
  done < <(
    find "${repodir}/" \
        … \
        -exec \
          grep -FZl -- 'CONFIG_CHECK' {} + |
      xargs -0rn 1 dirname  |
      sort  |
      uniq
  )

… which I think works? Either way, it begs the question of whether shellcheck could try to more explicitly identify cases of unsafe non-alphanumeric filename handling beyond cases of word-splitting currently reported - likely a whole can of worms 😯)

srcshelton avatar Feb 17 '25 16:02 srcshelton