[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: access exported var
From: |
Lawrence Velázquez |
Subject: |
Re: access exported var |
Date: |
Mon, 16 Jan 2023 00:32:01 -0500 |
User-agent: |
Cyrus-JMAP/3.7.0-alpha0-1187-g678636ba0d-fm-20230113.001-g678636ba |
On Mon, Jan 16, 2023, at 12:10 AM, Peng Yu wrote:
> The results are different depending on whether the variable is a
> scalar or an array (the result is always null). Why is it so?
Because arrays cannot be exported to the environment.
> Why even in the last case, "a" of the first element of the array
> cannot be retrieved?
Because the array is not in the environment.
This slightly different version of your test might make this clear
(you could also use env(1) or whatever other tool you like):
$ cat foo.c
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
const char *s = getenv(argv[1]);
if (s) {
printf("<%s>\n", s);
} else {
puts("not found");
}
return 0;
}
$ cc foo.c
$ export W=''
$ ./a.out W
<>
$ export X=abc
$ ./a.out X
<abc>
$ declare -A Y=([a]=1 [b]=2)
$ export Y
$ ./a.out Y
not found
$ Z=(a b)
$ export Z
$ ./a.out Z
not found
--
vq
- Re: access exported var, (continued)
- Message not available
- Re: access exported var, Peng Yu, 2023/01/16
- Re: access exported var, Lawrence Velázquez, 2023/01/16
- Re: access exported var, Matthew Mueller, 2023/01/16
- Re: access exported var, Greg Wooledge, 2023/01/16
- Re: access exported var, Matthew Mueller, 2023/01/16
Re: access exported var, Chet Ramey, 2023/01/16
Re: access exported var,
Lawrence Velázquez <=