我在OpenWrt中開發了一個腳本shell,如下所示,我注意到腳本結尾處的註釋中顯示了一個奇怪的行爲(「返回」)。它返回43而不是9003和45而不是9005,你對這種行爲有任何解釋嗎?在shell腳本中返回命令
#!/bin/sh
get_value() {
case "$1" in
aa)
if [ "$2" = "1" ]; then
return 9003
fi
# function fn1 to execute
fn1
return 0
;;
bb)
if [ "$2" = "1" ]; then
return 9003
fi
# function fn2 to execute
fn2
return 0
;;
cc)
if [ "$2" = "1" ]; then
return 9003
fi
# function fn3 to execute
fn3
return 0
;;
esac
return 9005
}
# when a call get_value
get_value aa 0
echo $?
# result 0
get_value aa 1
echo $?
# result 43 (not 9003)
get_value dd 1
echo $?
# result 45 (not 9005)