help-bash
[Top][All Lists]
Advanced

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

Re: access exported var


From: Peng Yu
Subject: Re: access exported var
Date: Sun, 15 Jan 2023 23:59:54 -0600

On 1/15/23, Kerin Millar <kfm@plushkava.net> wrote:
> 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.

But `echo "$Z"` print "a". Why bash can not treat exporting array as
exporting the first element?

-- 
Regards,
Peng



reply via email to

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