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

Re: 2 more questions



Uli Zappe wrote:
>1. Is there a way in zsh to pass the standard output to a parameter 
>   instead of the standard input of a command? I.e. I have
>
>      command1 | command2 parameter
>
>   and need the output of command1 as the parameter for command2

command2 "$(command1)"

>2. How do I pipe the elements of an array into a command? If I do a
>
>      echo $ARRAY | command
>
>   the elements are separated only by whitespace instead of newlines 
>   which will not work correctly especially if the elements possibly
>   contain whitespace themselves.

print -l "$ARRAY[@]" | command

but in the case of zero elements this will provide a single newline,
and it will produce ambiguous output if the array elements can contain
newlines.

command "$ARRAY[@]"

is the best interface, if it is feasible.

-zefram



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