Skip to content

zsh: support quoted $! to get the most recent background PID #1298

Closed

Description

@LangLangBart

❌ Fails to parse when $! is quoted

./shfmt --language-dialect zsh << 'EOF'
sleep 10 &
pid="$!"
EOF
# <standard input>:2:6: `${!foo}` is a bash/mksh feature; tried parsing as zsh

✅ Succeeds when unquoted

./shfmt --language-dialect zsh << 'EOF'
sleep 10 &
pid=$!
EOF

# sleep 10 &
# pid=$!

zsh docs

https://zsh.sourceforge.io/Doc/Release/Parameters.html#Parameters-Set-By-The-Shell


PS: Set setopt nobanghist in your shell to prevent history expansion from interfering when running the example.

EDIT1: nobanghist note added

Activity

  1. added a commit that references this issue on Mar 22, 2026
    0531734
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址