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

zip arrays exclude empty elements




I have an input string in form of 'A[-][B]' that I'd like to translate as follows:

1: A-B    ->  -a A -b B
2: A-     ->  -a A
3: A      ->  -a A
4: -B     ->  -b B
5: empty  ->  empty

The solution I found:
tmp=("${(@s.-.)crop}")
echo ${tmp[1]:+-a $tmp[1]} ${tmp[2]:+-b $tmp[2]}


But possible there is clearer and simpler solution, like

o=(-a -b)
echo ${o:^tmp}

or even
echo ${(-a -b):^${(@s.-.)crop}}


--
sergio.




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