3

I can't understand the way zsh 5.9 behaves when assigning $! to an array:

unset a b c

sleep 3 &

a=$!
b[1]=$!
c[1]=${!}

typeset -p a b c

output:

typeset a=21391
typeset -a b=( '$!' )
typeset -a c=( 21391 )

Getting b=( '$!' ) doesn't feel right... Is it a feature? A regression?

7
  • On Linux I get b=( 20769 ) with zsh 5.0.2 and b=( '$!' ) with zsh 5.5.1. Commented Aug 14, 2024 at 15:12
  • b[1]="$!" works as expected, too. It's just the bare case. Weird. Commented Aug 14, 2024 at 21:25
  • 1
    I'd report it as a bug Commented Aug 14, 2024 at 21:30
  • 1
    I was testing with 5.9; didn't get the unmatched error.... I bet it has something to do with history expansion, since ! is used for that. Commented Aug 15, 2024 at 5:33
  • 1
    I can reproduce it with zsh 5.8.1 on MacOS. Commented Aug 15, 2024 at 6:07

1 Answer 1

1

The problem's been fixed in commit 5977d3c


But IMHO it's best not to rely on arr[1]=$! anymore and use the following workaround to be portable across zsh versions:

arr[1]=${!}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.