我在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)