On Mon, Jan 16, 2023, at 1:05 AM, Kerin Millar wrote:
> On Sun, 15 Jan 2023 23:59:54 -0600
> Peng Yu <pengyu.ut@gmail.com> wrote:
>
>> But `echo "$Z"` print "a". Why bash can not treat exporting array as
>> exporting the first element?
>
> Technically, that would be possible.
For what it's worth, ksh exports indexed arrays that way, while zsh
behaves like bash (i.e., does not export), and yash synthesizes a
PATH-style scalar. (Of course, dash and POSIXly-correct yash don't
support arrays.)
% cat export_array.sh
foo=(a b c)
export foo
env | grep foo
% bash export_array.sh
% ksh export_array.sh
foo=a
% zsh export_array.sh
% yash export_array.sh
foo=a:b:c
% ARGV0=sh yash export_array.sh
export_array.sh:1: syntax error: invalid use of `('
% dash export_array.sh
export_array.sh: 1: Syntax error: "(" unexpected
--
vq