Target system bash give me parameter error when I use `local -n`. How am I allowed to solve?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















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.



#!/bin/bash

# clearCnt(src,dst)
clearCnt()

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
done

return


hdc=0
hh=
GT5849503583053053
ST5849503583053063
MT6849503583053053
KT5849503583053053
xxx

clearCnt hh hdc
exit


How am I allowed to solve this issue?










share|improve this question




























    0















    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.



    #!/bin/bash

    # clearCnt(src,dst)
    clearCnt()

    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
    done

    return


    hdc=0
    hh=
    GT5849503583053053
    ST5849503583053063
    MT6849503583053053
    KT5849503583053053
    xxx

    clearCnt hh hdc
    exit


    How am I allowed to solve this issue?










    share|improve this question


























      0












      0








      0








      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.



      #!/bin/bash

      # clearCnt(src,dst)
      clearCnt()

      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
      done

      return


      hdc=0
      hh=
      GT5849503583053053
      ST5849503583053063
      MT6849503583053053
      KT5849503583053053
      xxx

      clearCnt hh hdc
      exit


      How am I allowed to solve this issue?










      share|improve this question
















      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.



      #!/bin/bash

      # clearCnt(src,dst)
      clearCnt()

      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
      done

      return


      hdc=0
      hh=
      GT5849503583053053
      ST5849503583053063
      MT6849503583053053
      KT5849503583053053
      xxx

      clearCnt hh hdc
      exit


      How am I allowed to solve this issue?







      bash scripting bash-functions






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 2 at 12:48







      Sir Jo Black

















      asked Feb 2 at 12:34









      Sir Jo BlackSir Jo Black

      1965




      1965




















          1 Answer
          1






          active

          oldest

          votes


















          1














          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





          share|improve this answer

























          • 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








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f498280%2ftarget-system-bash-give-me-parameter-error-when-i-use-local-n-how-am-i-allow%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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





          share|improve this answer

























          • 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
















          1














          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





          share|improve this answer

























          • 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














          1












          1








          1







          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





          share|improve this answer















          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






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 2 at 13:07

























          answered Feb 2 at 12:49









          KusalanandaKusalananda

          132k17250413




          132k17250413












          • 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


















          • 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

















          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





          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





          @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






          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






          @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




          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






          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


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f498280%2ftarget-system-bash-give-me-parameter-error-when-i-use-local-n-how-am-i-allow%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?