Skip to content

Instantly share code, notes, and snippets.

@ryo0301
Created September 26, 2014 11:11
Show Gist options
  • Save ryo0301/f26189dedc81a6f11166 to your computer and use it in GitHub Desktop.
Save ryo0301/f26189dedc81a6f11166 to your computer and use it in GitHub Desktop.
シェルスクリプトでtry-catch-finally ref: http://qiita.com/ryo0301/items/7bf1eaf00b037c38e2ea
#!/bin/sh
set -eu
trap catch ERR
trap finally EXIT
function catch {
echo CATCH
}
function finally {
echo FINALLY
}
echo pre
cd $1
echo post
exit 0
$ ./test.sh /
pre
post
FINALLY
$ ./test.sh /root
pre
./test.sh: line 16: cd: /root: 許可がありません
CATCH
FINALLY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment