#1211·sh

zsh: support { try-list } always { always-list }

Author: LangLangBartCreated Oct 22, 2025Updated Sep 7, 2026
Labelszsh

Extract from the 4.2.0 release notes (released on 19 March 2004):

A new try block and always block syntax has been introduced to make it easier to ensure the shell runs important tidy-up code in the event of an error. It also runs after a break, continue, or return, including a return forced by the ERR_RETURN option (but not an exit, which is immediate). The syntax is:

{ try-block-list } always { always-block-list }

where no newline or semicolon may appear between } and always. [...]

Source: https://zsh.sourceforge.io/releases.html#:~:text=Changes%20since%20zsh%20version%204.2.0

bash
{
  command_that_might_fail
} always {
  echo "This code is always executed."
}

Zsh docs: https://zsh.sourceforge.io/Doc/Release/Shell-Grammar.html#:~:text=try%2Dlist&text=always&text=always%2Dlist