2022-06-04 - bash and RAII - continued

couple days ago i wrote about RAII in bash. i forgot to mention 1 more thing there. when cleanup procedure is more complicated than simple rm -rf foobar it's worth to make it a separate function:

# ...
function cleanup
{
  rm -rf "$VAR_TO_SANITIZE"
  rm -fv /path/to/lock
  umount /media/foobar
}
trap cleanup EXIT
# ...