help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: access exported var


From: Kerin Millar
Subject: Re: access exported var
Date: Mon, 16 Jan 2023 05:52:01 +0000

On Sun, 15 Jan 2023 23:10:41 -0600
Peng Yu <pengyu.ut@gmail.com> wrote:

> 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?

Bash cannot export arrays. It's not particularly surprising. The value of an 
environment variable is a NUL-terminated string; there's no universally safe 
delimiter that could be used to join the array's elements.

-- 
Kerin Millar



reply via email to

[Prev in Thread] Current Thread [Next in Thread]