예. 예를 들면 다음과 같습니다.
$ exitwith() { return $1; }
$ for stat in {0..10}; do
> if exitwith $stat; then
> echo "An exit status of $stat is considered true"
> else
> echo "An exit status of $stat is considered false"
> fi
> done
An exit status of 0 is considered true
An exit status of 1 is considered false
An exit status of 2 is considered false
An exit status of 3 is considered false
An exit status of 4 is considered false
An exit status of 5 is considered false
An exit status of 6 is considered false
An exit status of 7 is considered false
An exit status of 8 is considered false
An exit status of 9 is considered false
An exit status of 10 is considered false
그러나 종료 상태는 8 비트 부호없는 정수이므로 범위는 0에서 255까지만 가능하기 때문에 실제로는 그보다 약간 더 복잡합니다. 해당 범위 밖의 값은 모듈로 256을 해당 범위로 줄입니다.
$ for stat in -2 -1 255 256 257; do
> if exitwith $stat; then
> echo "An exit status of $stat (actually $?) is considered true"
> else
> echo "An exit status of $stat (actually $?) is considered false"
> fi
> done
An exit status of -2 (actually 254) is considered false
An exit status of -1 (actually 255) is considered false
An exit status of 255 (actually 255) is considered false
An exit status of 256 (actually 0) is considered true
An exit status of 257 (actually 1) is considered false