2023年8月2日发(作者:)
linux-shell-if如何判断truefalse以查找⽂件为例:同级⽬录下存在find 不存在find1#!/bin/bashif test -e find;then echo "ok"
else echo "no"fiif [ -e find ];then echo "ok"
else echo "no"fiokok#!/bin/bashif test -e find1;then echo "ok"
else echo "no"fiif [ -e find1 ];then echo "ok"
else echo "no"finono#!/bin/bashtest -e findecho $?test -e find1echo $?[ -e find ]echo $?[ -e find1 ]echo $?0101结论if 是通过其后的命令执⾏完成的结果$? = 0 #执⾏成功$? = 1 #执⾏失败从⽽判断条件的真/假#!/bin/bashtest -e findecho $?test -e find1echo $?[ -e find ]echo $?[ -e find1 ]echo "⼲扰" #执⾏成功 $?=0
echo $?010⼲扰0
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1690917861a463156.html
评论列表(0条)