shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

SC2034: Passing by reference is not recognized as usage

Open yoosiba opened this issue 4 years ago • 2 comments

For bugs

  • Rule Id: SC2034
  • My shellcheck version: 0.7.0
  • [X] The rule's wiki page does not already cover this (see https://shellcheck.net/wiki/https://github.com/koalaman/shellcheck/wiki/SC2034)
  • [X] I tried on shellcheck.net and verified that this is still a problem on the latest commit

Here's a snippet or screenshot that shows the problem:

#!/usr/bin/env bash

process_arr() {
    local -n my_arr=$1
    my_arr+=('World')
    echo "${my_arr[@]}"
}

main() {
    local arr=()
    arr=('Hello')   #SC2034
    process_arr arr # pass by reference
}

main

Here's what shellcheck currently says:

Line 11:
    arr=('Hello')   #SC2034
    ^-- SC2034: arr appears unused. Verify use (or export if used externally).

Here's what I wanted or expected to see:

Nothing. Passing by reference should be recognized as valid usage.

yoosiba avatar May 17 '20 08:05 yoosiba

Issue also exists with shellcheck 0.8.0

robstoll avatar Jun 13 '22 11:06 robstoll

+1 for this, very annoying and forces the variable export

ciros88 avatar Nov 07 '23 07:11 ciros88