Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Function-scoped parameters?



On Wednesday, February 23, 2011, Benjamin R. Haskell <zsh@xxxxxxxxxx> wrote:
> The use case is that I want to assign a local parameter 'temp' to be set to the name of a temporary file.  If anything goes wrong in the function, I'd like that temporary file to be removed, but I don't want 'temp' to leak out of the function scope.

That's what "always" is for.

dosomething() {
  emulate -L zsh
  local temp=$(mktemp)
  setopt err_return
  {
    # ...
  } always {
    (( $+temp )) && rm $temp
  }
}



Messages sorted by: Reverse Date, Date, Thread, Author