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

Re: Change on stdout



On 2009-07-31 at 17:52 +0200, tartifola@xxxxxxxxx wrote:
> I need to operate a transformation on the standard output
> of a command. The output is a list of numbers
> 
> 1 5 8 ...
> 
> and I like to have it transformed in
> 
> a1=1,a2=5,a3=8,...
> 
> Any suggestion? 

% print '1 5 8 223' | read nums; n=1; print "a$n=${(ej:,a$((++n))=:)${(z)nums}}" 
a1=1,a2=5,a3=8,a4=223

Note that string substitution ${var//pattern/replacement} only evaluates
the replacement once, but the arithmetic expansion on the array-joining
string is evaluated each time.

Regards,
-Phil



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