Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, they work in zsh, with one extremely small change: The referenced variable needs to exist.

Try this (tested with zsh 5.9 on archlinux):

    foo='PWD[$(echo hahaha >&2)0]+42'
    [[ "$foo" -eq 5 ]]
In bash, this would also print "hahaha" with "a" (or any other possible variable name) instead of "PWD", that's why many think it doesn't work at all in zsh.

I'm pretty sure zsh has an optimization where it skips the indexing if the variable doesn't exist, which happens to sometimes stop this. But since you can just reference variables like PWD, that you know exist, it's not really a security improvement.



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: