[Cialug] Bash Array Variables

Todd Walton tdwalton at gmail.com
Thu Aug 11 14:59:01 UTC 2022


$ cat test.sh
#!/bin/bash
echo "VARS1: ${VARS1[@]}"
echo "BARS2: $BARS2"

$ VARS1=(tom jerry)
$ BARS2=bradybunch
$ ./test.sh
VARS1:
BARS2:

$ export VARS1=(tom jerry)
$ export BARS2=bradybunch
$ ./test.sh
VARS1:
BARS2: bradybunch

$ # zomg, no VARS1
$ man bash | awk '/^BUGS/,0'
BUGS
       It's too big and too slow.

       There are some subtle differences between bash  and  traditional
 ver‐
       sions of sh, mostly because of the POSIX specification.

       Aliases are confusing in some uses.

       Shell builtin commands and functions are not stoppable/restartable.

       Compound  commands  and  command sequences of the form `a ; b ; c'
are
       not handled gracefully when process suspension is attempted.   When
 a
       process is stopped, the shell immediately executes the next command
in
       the sequence.  It suffices to place the sequence of  commands
 between
       parentheses  to  force  it  into a subshell, which may be stopped as
a
       unit.

       Array variables may not (yet) be exported.

       There may be only one active coprocess at a time.

GNU Bash 5.1                   2020 October 29
 BASH(1)

$ # "Array variables may not (yet) be exported."


More information about the Cialug mailing list