linux - #!/bin/csh Cshell 检查查找结果 if else
问题描述
目标:检查查找结果,如果为空则回显某些内容,如果不是则回显查找结果
#!/bin/csh
set mtime = 0;
echo "<i>Title</i>" >> $outputfile
set text=`find start*middle*.txt -mtime $mtime -ls`
echo "$text" >> $outputfile
我已经尝试了以下(全部失败)......
if (-f "$text" ) then
echo Exists
else
echo No such file
endif
-
if [[ -n $(find start*middle*.txt -mtime $mtime -ls) ]]
then
echo "res" >> $outputfile
fi
-
if [[ -n "$text" ]]
then
echo "res" >> $outputfile
fi
解决方案
#!/bin/csh
set outputfile = test
set mtime = 0;
echo "<i>Title</i>" >> $outputfile
set text=`find start*middle*.txt -ls`
if ("$text" != "") then
echo "exists"
else
echo "dosn't exist"
endif
echo "$text" >> $outputfile
如果您需要使用该-mtime
选项,则值为 0 是不正确的。如果要列出在最后一天创建的文件,则需要-mtime -1
2 天-mtime -2
推荐阅读
- sql - 从 SQL Server 中的另一个表替换列中的多个值
- telerik - 从 asp.net 中的 Web Api 加载 RadComboBoxItemData[]
- json - Swagger 文档中的 camelCase
- tensorflow - 训练丢失图是否显示过拟合?深度 Q 学习
- javascript - Puppeteer:延迟图像未在无头模式下加载
- java - Why doesn't the file get deleted and renamed?
- java - Unable to modify fxml elements on Stage start
- python - 如何使用 numpy.char.join?
- ios - 如何将数据对象传递给嵌入在不同情节提要的导航控制器中的视图控制器
- python - 如何数值求解矩阵方程?