[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] append to $@ one by one
From: |
Andreas Kusalananda Kähäri |
Subject: |
Re: [Help-bash] append to $@ one by one |
Date: |
Sun, 20 Oct 2019 10:35:23 +0200 |
User-agent: |
Mutt/1.12.2 (2019-09-21) |
On Sat, Oct 19, 2019 at 08:11:55PM -0500, Peng Yu wrote:
> Hi,
>
> I use the following code to read from stdin and set $@ at once. But it
> involves an additional variable "a". Is there a way to avoid such a
> variable by appending to $@ one by one (but it should not be too slow,
> so `set -- "$@" "$x"` will not work.)
Using
set -- "$@" "$x"
would be the correct solution to avoid an additional array variable.
Could you expand on the "too slow" issue? If that is too slow compared
to using an array, then I must assume that you have so much data that
doing whatever you're doing in another language would be preferable.
Also, is the use of an additional array variable not wanted due to
purely aesthetic reasons?
Regards,
Kusalananda
>
> while IFS= read -r x; do
> a+=("$x")
> done
> set -- "${a[@]}"
>
> --
> Regards,
> Peng
- [Help-bash] append to $@ one by one, Peng Yu, 2019/10/19
- Re: [Help-bash] append to $@ one by one, Daniel Mills, 2019/10/19
- Re: [Help-bash] append to $@ one by one,
Andreas Kusalananda Kähäri <=
- Re: [Help-bash] append to $@ one by one, Peng Yu, 2019/10/20
- Re: [Help-bash] append to $@ one by one, Eli Schwartz, 2019/10/20
- Re: [Help-bash] append to $@ one by one, Gerard E. Seibert, 2019/10/20
- Re: [Help-bash] append to $@ one by one, Peng Yu, 2019/10/20
- Re: [Help-bash] append to $@ one by one, Eduardo Bustamante, 2019/10/20
- Re: [Help-bash] append to $@ one by one, Peng Yu, 2019/10/20
- Re: [Help-bash] append to $@ one by one, Andreas Kusalananda Kähäri, 2019/10/21
Re: [Help-bash] append to $@ one by one, Jesse Hathaway, 2019/10/21