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

Re: Change on stdout



On Fri, Jul 31, 2009 at 05:52:07PM +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,...

This is inelegant (like my knowledge of the shell) but should work.

$ nums=$(your_command)
$ numArray=( ${=nums} )
$ for (( n = 1; n <= ${#numArray}; n++))
echo -n "a${n}=${numArray[$n]},"
done
echo

-- 
A smart man knows everything. A wise man knows everybody.



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