I have a script that contains a clearCnt function that works correctly on my Linux system with bash version GNU bash, version 4.3.48, but doesn't works correctly on the Linux target system. The bash ( version: GNU bash, version 4.1.2(1) ) on the target system doesn't accept the command local -n.

The following code is an extract of the script that shall use the function clearCnt more times during the "main" script flow and shall use also a lot of arrays different from hh.


# clearCnt(src,dst)    
local i=0
local -n src=$1
local -n dst=$2

while test ${src[$i]} != 'xxx'; do

    let dst[$i]=0
    echo ${src[$i]} ${dst[$i]}

    let i=i+1



clearCnt hh hdc

How am I allowed to solve this issue?


local -n would define a name reference variable.

Update the bash on the target system to bash-4.3 or newer (this is the release of the shell that introduced name references), or install that version of the shell elsewhere on the system and make your scripts use that instead of /bin/bash.

Note also that every single variable expansion in that code must be double quoted. For example,

while test ${src[$i]} != 'xxx'; do

should be written

while test "${src[$i]}" != 'xxx'; do

or as

while [ "${src[$1]}" != 'xxx' ]; do
  • I cannot update the bash on the target system. It's a production system and we have security procedure that only administrator may do ... and I'm not he! – Sir Jo Black Feb 2 at 12:51
  • @SirJoBlack Good, then make the administrator do it. It's their job – Kusalananda Feb 2 at 12:52
  • Kusalananda, Ah ah ah ah ah ... do you think that I've not tried this way? There are reasons why it is not as simple as it seems. – Sir Jo Black Feb 2 at 12:54
  • @SirJoBlack Are you telling me you have a system administrator that is preventing you from carrying out your job? What do the managers think about that? – Kusalananda Feb 2 at 12:55
  • 1
    Go through whatever usual channels you have for getting software installed on the system and get them to install bash-4.3 or newer elsewhere. There is no need to replace /bin/bash with a newer version. Once they have done so, point to that bash in your scripts' #!-line. Alternatively, solve your problem in a language that is available on the machine. – Kusalananda Feb 2 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.