Created
September 26, 2014 11:11
-
-
Save ryo0301/f26189dedc81a6f11166 to your computer and use it in GitHub Desktop.
シェルスクリプトでtry-catch-finally ref: http://qiita.com/ryo0301/items/7bf1eaf00b037c38e2ea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./test.sh / | |
pre | |
post | |
FINALLY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./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