bash - 如果搜索文件时 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
解决方案
推荐阅读
- azure - 如何为所有环境设置通用阶段管道?
- asp.net - 如何在 ASP.NET Core Web API 2.1 中添加 WCF 服务引用
- r - 一元运算符的无效参数 - R Shiny
- ios - 在 Highcharts 中加载图表时显示加载指示器
- c++ - 我如何清除数组
- node.js - 使用 mongodb、mongoose 和 nodejs 设置限制和偏移后获取集合总数
- ffmpeg - 如何从捕获设备捕获带有音频的简单视频输入
- java - EditText getText 在按钮单击中不起作用
- javascript - 未捕获的 ReferenceError,Splide 未在 HTMLDocument 中定义
- python - 如何为具有动态添加属性的类实例定义类型提示?