bash는 명령 치환 잘못된 종료 상태를 수신이 예는 떠들썩한 파티와 맥 엘 캐피 테스트되었습니다
main_script.sh :
참고 : 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가하는 일을 잘 알고 있습니다. 나는 단순히 출력을 가능한 한 명확하게하려고 노력했다. 나는 그 문제가 무엇인지를 안다, 왜 나는 그럴까 궁금하다. 무슨 일이 있어도 지역 변수가 0을 반환한다고 선언 한 것 같아. 배시 버그 같아? – arctelix