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