以ls举例,中间具体校验啥随便替换。
while true do read -p "输入你想查看的路径:" path ls $path test $? -eq 0 && break || echo "path not exists" done
test $? -eq 0
xxx && command1 || command2
效果如下: