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

Array index



What is the easiest way to find the index of a specific element in an
array, apart from using a for loop? The statement

	(( i = array[(i)$value] ))

fails if $value contains special characters like parentheses. I tried
quotes on different parts of the expression, but without success.
Example:

	x='a(b)'
	arr=($x bla)
	print $arr[(i)$x]	# 3
	print $arr[(i)"$x"]	# 3
	print $arr["(i)$x"]	# zsh: bad math expression: unbalanced stack

Any ideas?

	Bernd
-- 
Bernd Eggink
Regionales Rechenzentrum der Universitaet Hamburg
eggink@xxxxxxxxxxxxxxxxxx
http://www.rrz.uni-hamburg.de/eggink/BEggink.html



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