似乎无法使它评估为真实
is_equal () {
in="$1"
if [[ "$in" == "385" ]]; then
return 0
else
return 1
fi
}
a= is_equal 385
if [[ "$a" ]]; then
echo "equal"
else
echo "NOT equal"
fi
$ ./equal_nums.sh
NOT equal
$
您的函数处于退出状态,但没有输出。您的变量$a
将始终为空,因此[[ $a ]]
测试将始终为“ false”
您真正想要的是:
if is_equal 42; then ...
但是你认为你想要的是
is_equal 42 # don't capture the output
a=$? # but do grab the exit status
if [[ $a -eq 0 ]]; then ...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句