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

bug in parameter expansion



This issue was initially reported against shell code delivered in
cloud-init at [1], but it seems to me to be a bug in zsh's posix shell
behavior.

$ for shell in /bin/dash /bin/bash /bin/ksh /bin/zsh; do \
  echo "=== $shell ==="; $shell -c 'echo "${1%%=*}"' \
  -- A=B; done
=== /bin/dash ===
A
=== /bin/bash ===
A
=== /bin/ksh ===
A
=== /bin/zsh ===
zsh:1: * not found

It also has the issue when matching prefix (#):
$ zsh -c 'echo ${1#=?}' -- =AB
zsh:1: ? not found
$ bash -c 'echo ${1#=?}' -- =AB
B

It is seemingly easily worked around by escaping the '=' like:
  $ zsh -c 'echo "${1%%\=*}"' -- A=B
  A
or:
  zsh -c 'equal="="; echo "${1%%${equal}*}"' -- A=B
  A

Scott
--
[1] https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1073077



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