[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] append to $@ one by one
From: |
Daniel Mills |
Subject: |
Re: [Help-bash] append to $@ one by one |
Date: |
Sat, 19 Oct 2019 21:15:57 -0400 |
On Sat, Oct 19, 2019 at 9:12 PM Peng Yu <address@hidden> 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.)
>
> while IFS= read -r x; do
> a+=("$x")
> done
> set -- "${a[@]}"
>
> --
> Regards,
> Peng
>
>
Why not just append all at the same time?
while IFS= read -r x; do
a+=("$x")
done
# some other logic that sets x and y
set -- "$a[@]}" "$x" "$y"
Alternatively, just append to the array and then do your set. There's no
method to append to the positional parameters, it's either setting them all
at once or not at all.
- [Help-bash] append to $@ one by one, Peng Yu, 2019/10/19
- Re: [Help-bash] append to $@ one by one,
Daniel Mills <=
- Re: [Help-bash] append to $@ one by one, Andreas Kusalananda Kähäri, 2019/10/20
- 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