help-bash
[Top][All Lists]
Advanced

[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.


reply via email to

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