この例では、bashのbashコマンド置換が不正終了ステータスを受信
main_script.shを搭載したMacエルキャピタンで試験した:
注:func_aとfunc_bは、その行を除いて同一でありますローカル変数
output
が宣言されています。
func_a() {
local output
output="$(./external.sh some_function)"
if [ $? -eq 0 ];then
echo "A zero result ($?) -> $output <- end"
else
echo "A other result ($?) -> $output <- end"
fi
}
func_b() {
local output="$(./external.sh some_function)"
if [ $? -eq 0 ];then
echo "B zero result ($?) -> $output <- end"
else
echo "B other result ($?) -> $output <- end"
fi
}
func_a
func_b
external.sh:
私が出力されmain_script実行some_function() {
echo "this is the output"
return 1
}
"[email protected]"
:
A other result (1) -> this is the output <- end
B zero result (0) -> this is the output <- end
のためにどのような理由と同じラインなどのローカル変数の宣言コマンドの代替は結果に影響しますか?これはバグかもしれませんか?何か不足していますか?
これは役に立つかもしれません:[bashスクリプトのデバッグ方法](http://unix.stackexchange.com/q/155551/74329) – Cyrus
bashスクリプトのデバッグ方法とset -xの機能をよく理解しています。私は出力を可能な限り明確にしようとしました。私は問題が何であるか知っている、なぜ今は私は不思議。何があってもローカルのvarがゼロを返すと宣言したようです.bashバグのようですか? – arctelix