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

Re: [BUG] quoting within bracket patterns has no effect



On Jan 23, 12:17am, Martijn Dekker wrote:
}
} However, for variables there is now a new problem, the opposite of the
} old one: unlike in every other shell, a range is not recognised even if
} the variable is *not* quoted. So quoting a variable still has no effect,
} it's just that range parsing from variables was disabled altogether. The
} following code:
} 
} myrange='a-z'
} somevar='c'
} case $somevar in
} ( *[$myrange]* )  echo "$somevar is part of $myrange" ;;
} esac
} 
} outputs "c is part of a-z" on every shell except current zsh.

This is related to long-standing behavior for zsh in native mode.

In as-close-as-zsh-has-to-POSIX mode:

schaefer[655] ARGV0=sh Src/zsh
$ myrange='a-z'
$ somevar='c'
$ case $somevar in
> ( *[$myrange]* )  echo "$somevar is part of $myrange" ;;
> esac
c is part of a-z
$ 


In native mode you need to use $~param to activate pattern characters
in the expanded value:

schaefer[656] Src/zsh -f
torch% myrange='a-z'
torch% somevar='c'
torch% case $somevar in
case> ( *[$~myrange]* )  echo "$somevar is part of $myrange" ;;
case> esac
c is part of a-z
torch% 


It's true that needing this inside a character class now differs from
previous versions of zsh for native mode.  I'm not sure it's possible
to have it both ways.



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