Associative arrays are local by default

后端 未结 5 1788
故里飘歌
故里飘歌 2021-02-01 14:50

Associative arrays seem to be local by default when declared inside a function body, where they should be global. The following code

#!/bin/bash

f() {
    decla         


        
5条回答
  •  灰色年华
    2021-02-01 15:10

    From: Greg Wooledge
    Sent: Tue, 23 Aug 2011 06:53:27 -0700
    Subject: Re: YAQAGV (Yet Another Question About Global Variables)

    bash 4.2 adds "declare -g" to create global variables from within a function.

    Thank you Greg! However Debian Squeeze still has Bash 4.1.5

提交回复
热议问题