呼び出し元。set -exののち、スタートメッセージを表示 -> 引数で渡されたシェルスクリプトをsource -> エンドメッセージ表示
呼び出される子供。
set -eのち、スタートメッセージを表示 -> falseを実行(つまりここでコマンド失敗) -> エンドメッセージ表示
スタートメッセージを表示 -> falseを実行(つまりここでコマンド失敗) -> エンドメッセージ表示 ここではset -eとかやらない。
echo start ko | |
false | |
echo end ko |
function func() { | |
echo $1 | |
return 1 | |
} | |
echo start ko | |
func 'do func' | |
echo end ko |
set -e | |
echo start ko | |
false | |
echo end ko |
set -ex | |
echo oya start | |
source $@ | |
echo oya end |
set -ex | |
trap 'echo !trapped!' EXIT | |
echo oya start | |
source $1 || echo error | |
echo oya end |
$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ sh --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ bash parent.sh child_no_set_e.sh
+ echo oya start
oya start
+ source child_no_set_e.sh
++ echo start ko
start ko
++ false
$ bash parent.sh child_set_e.sh
+ echo oya start
oya start
+ source child_set_e.sh
++ set -e
++ echo start ko
start ko
++ false
# bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
# sh --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
# bash parent.sh child_set_e.sh
+ echo oya start
oya start
+ source child_set_e.sh
++ set -e
++ echo start ko
start ko
++ false
# bash parent.sh child_no_set_e.sh
+ echo oya start
oya start
+ source child_no_set_e.sh
++ echo start ko
start ko
++ false
mac