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: 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



reply via email to

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