[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
access exported var
From: |
Peng Yu |
Subject: |
access exported var |
Date: |
Sun, 15 Jan 2023 23:10:41 -0600 |
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
- access exported var,
Peng Yu <=
- Re: access exported var, Kerin Millar, 2023/01/16
- Re: access exported var, Chet Ramey, 2023/01/16
- Re: access exported var, Peng Yu, 2023/01/16
- Re: access exported var, Chet Ramey, 2023/01/16
- Re: access exported var, Peng Yu, 2023/01/16
- Re: access exported var, Leonid Isaev, 2023/01/16