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

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



On Jan 26,  4:03am, Martijn Dekker wrote:
}
} In normal variable expansion, setting the option SH_WORD_SPLIT causes
} unquoted $var to be equivalent to ${~var} in variable expansion.
} Wouldn't it make sense to have SH_WORD_SPLIT activate pattern characters
} in unquoted variables in range expressions as well?

Look again at my first example from the previous message:

schaefer[691] Src/zsh -f
torch% emulate sh
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% print $ZSH_PATCHLEVEL
zsh-5.2-103-g69c86cd

What about that is incorrect?  You need $~myrange for "emulate zsh" but
NOT for "emulate sh", unless I'm missing something.

Also it's never been "setopt shwordsplit" that enables patterns in a
parameter expansion, rather it's "setopt globsubst":

schaefer[692] Src/zsh -f
torch% x='c*h'
torch% print $x
c*h
torch% setopt shwordsplit
torch% print $x
c*h
torch% setopt globsubst
torch% print $x
config.h config.modules.sh

What I was pointing out when I said "I'm not sure it's possible to have
it both ways" has ONLY to do with "emulate zsh".  The problem is that
the parsing happens at two different places -- at the time $myrange is
expanded, I don't believe the parameter substitution code knows it's
inside a character set in an active pattern; so there's no way to
temporarily activate globsubst except by explicity doing so.

This may be a case where native zsh is incompatible with POSIX at a
fairly fundamental level; old working zsh scripts are potentially going
to break, and I don't think we can do anything about it unless we want
to tell POSIX to go pound sand.



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