On Thu, Dec 12, 2019 at 1:10 PM Léa Gris <lea.g...@noiraude.net> wrote:
> Hello, > > Depending on how an empty array is declared, it is not stored with the > same state. > > # Empty array declared without parenthesis > unset myArr > declare -a myArr > typeset -p myArr > echo "${#myArr[@]}" > > output: > declare -a myArr > 0 > Here, you haven't yet defined a parameter named myArr; you have only set the array attribute on the name myArr. You can see something similar with other attributes: $ declare -i x $ [[ -v x ]] || echo "x not defined" x not defined $ declare -p x declare -i x > > # Empty array declared without parenthesis > unset myArr > declare -a myArr=() > typeset -p myArr > echo "${#myArr[@]}" > > output: > declare -a myArr=() > 0 > > With the assignment, you have an actual parameter named myArr. Continuing the integer attribute example from above, $ x=3 $ declare -p x declare -i x="3" $ [[ -v x ]] || echo "x not defined" # No output -- Clint