Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: xargs with zsh function



Bart Schaefer wrote on Sun, Jan 17, 2021 at 19:10:10 -0800:
> What you really want to do is write a nested shell loop that consumes
> N lines, then runs my_function, then does that again until it runs out
> of input; and pipe to that loop.  There are a bunch of ways to do
> that.  E.g.:
> 
> ... | while (true)
>   do
>     set --
>     for i in {1..10}
>     do
>       read $i || break
>     done
>     my_function "$@"
>     [[ $# -eq 10 ]] || break
>   done

If it's fine to call the function with the arguments one at a time, then the
following should do:

    «| xargs -n1 | while IFS= read -r line; do f "${line}"; done»




Messages sorted by: Reverse Date, Date, Thread, Author