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

Re: array matching: inconsistent behaviour ?



On Wed, 09 Jan 2013 12:00:34 +0530
rahul <rahul2012@xxxxxxxxx> wrote:
> Or am I doing the matching wrong? I am storing file names in an array.
> Later I match filenames against those in the array for various
> purposes. The filenames contain spaces and in this unfortunate case
> round brackets. File names with brackets are failing the match.
> 
> FOO=()
> x="a file"
> y="a(file)b"
> 
> FOO+=($x)
> FOO+=($y)
> 
> print $FOO[(i)$x]
> print $FOO[(i)$y]
> 
> #  Now I found, that if i quote the string while matching then the
> comma file matches, but now the space file fails.
> 
> print $FOO[(i)$x:q]
> print $FOO[(i)$y:q]

You're not exactly doing anything wrong, but quoting here has alwas been
a bit funny to allow (some forms of) pattern matching.  To ensure an
exact string match you can use the (e) flag...

% print $FOO[(ie)$x]
1
% print $FOO[(ie)$y]
2

pws



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