I use the following C code to check env var.
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
const char *s=getenv(argv[1]);
puts(s);
return 0;
}
The results are different depending on whether the variable is a
scalar or an array (the result is always null). Why is it so? Why even
in the last case, "a" of the first element of the array cannot be
retrieved?
$ export X=abc
$ ./main.exe X
ABC
$ declare -A Y=([a]=1 [b]=2)
$ export Y
$ ./main.exe Y
(null)
$ declare -a Z=([0]=a [1]=b)
$ export Z
$ ./main.exe Z
(null)
$ echo "$Z"
a
--
Regards,
Peng