Skip to main content
Became Hot Network Question
Spelling in title
Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

try/finalllyfinally with bash shell

Source Link
Alexander Mills
  • 10.9k
  • 27
  • 120
  • 214

try/finallly with bash shell

I have these three lines:

  export bunion_uds_file="$bunion_socks/$(uuidgen).sock";
  "$cmd" "$@" | bunion
  rm -f "$bunion_uds_file"

I need to make sure the last line always executes..I could do this:

  export bunion_uds_file="$bunion_socks/$(uuidgen).sock";
  (
    set +e
    "$cmd" "$@" | bunion
    rm -f "$bunion_uds_file"
  )

or maybe like this:

  export bunion_uds_file="$bunion_socks/$(uuidgen).sock";
  "$cmd" "$@" | bunion && rm -f "$bunion_uds_file" || rm -f "$bunion_uds_file"

I assume creating the subshell and using set +e is slightly less performant etc.