在bash脚本中使用if和boolean函数:if当函数返回true时,conditio
发布时间:2020-12-15 22:13:43 所属栏目:安全 来源:网络整理
导读:is_dir_empty(){ for file in "$1" do if [ "$file" != "$1" ]; then return 0 fi done echo "return 1" return 1}file="/home/tmp/*.sh"if is_dir_empty "$file"; then echo "empty"else echo "not empty"fi 它输出 return 1not empty 所以is_dir_empty返回
is_dir_empty(){ for file in "$1" do if [ "$file" != "$1" ]; then return 0 fi done echo "return 1" return 1 } file="/home/tmp/*.sh" if is_dir_empty "$file"; then echo "empty" else echo "not empty" fi 它输出 return 1 not empty 所以is_dir_empty返回1,但如果条件评估为假某事……为什么? 解决方法
因为shell脚本遵循Unix惯例,期望实用程序为成功返回零而对于失败则返回非零,因此布尔条件被反转.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |