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

Re: virtual files?



On Apr 19, 11:32pm, Benjamin R. Haskell wrote:
}
} Using the `=()` substitution ZyX mentions:
} 
}   () {
}     local tmp=$1
}     wget -q $link -O $tmp
}     echo -n \$
}     grep \"answer\" $tmp | cut -d \$ -f 2 | cut -d \< -f 1
}   } =(:)
} 
} The '() { ... }' construct is an anonymous function, just for controlling
} the scope of the temporary file, and for passing it in as a positional
} parameter.  It has the disadvantage that it won't remove the tmp file if
} something goes wrong.

In fact the point of using =(:) is that it WILL remove the tmp file if
something goes wrong (unless it's something completely catastrophic like
the shell itself crashing, but in that case an explicit "rm" wouldn't
work either).

Instead of exit traps, you can use "always" blocks:

  () {
    local tmp=$1;
    {
      : do stuff with $tmp
      exit
    } always {
      rm $tmp
    }
  } =(:)



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