首页 > 解决方案 > 如果搜索文件时 elif 不起作用

问题描述

当我尝试使用 if elif 检查文件夹中的文件时,它没有正确进入循环

if [ -e "~/file" ]; then 
   echo "abc"
elif   [ -f "$DIR/file" ]; then
  echo "bbbc"

else 
    echo "both the files does not exists - throwing error"
fi

有一个文件“~/file”,它直接进入 if 和 elif 并返回说 echo“这两个文件都不存在 - 抛出错误”

但是当我尝试否定操作时,它会进入并检查文件

if [ ! -e "~/file" ]; then

标签: bashshellif-statementunix

解决方案


推荐阅读