Skip to main content
edited body
Source Link
bishop
  • 3.2k
  • 2
  • 18
  • 31

Though zsh doesn't do split+glob upon parameter expansion, it still does empty removal, so that's still one reason you want to quote variables there, so:

print -rl -- "$var[@]"

Or

print -rl -- "${(@})var}"

Those @ are to get Bourne "$@"-like behaviour.

For elements 1 to 5:

print -rl -- "${(@)var[1,5]}"

The ksh-like variant will also work:

print -rl -- "${(@)var:0:5}"

Though zsh doesn't do split+glob upon parameter expansion, it still does empty removal, so that's still one reason you want to quote variables there, so:

print -rl -- "$var[@]"

Or

print -rl -- "${(@}var}"

Those @ are to get Bourne "$@"-like behaviour.

For elements 1 to 5:

print -rl -- "${(@)var[1,5]}"

The ksh-like variant will also work:

print -rl -- "${(@)var:0:5}"

Though zsh doesn't do split+glob upon parameter expansion, it still does empty removal, so that's still one reason you want to quote variables there, so:

print -rl -- "$var[@]"

Or

print -rl -- "${(@)var}"

Those @ are to get Bourne "$@"-like behaviour.

For elements 1 to 5:

print -rl -- "${(@)var[1,5]}"

The ksh-like variant will also work:

print -rl -- "${(@)var:0:5}"
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k

Though zsh doesn't do split+glob upon parameter expansion, it still does empty removal, so that's still one reason you want to quote variables there, so:

print -rl -- "$var[@]"

Or

print -rl -- "${(@}var}"

Those @ are to get Bourne "$@"-like behaviour.

For elements 1 to 5:

print -rl -- "${(@)var[1,5]}"

The ksh-like variant will also work:

print -rl -- "${(@)var:0:5}"