unix shell ksh:if语句获胜';我不能同时执行这两部分
伙计们,我的if语句只是执行第一部分,而else永远不会执行,即使尝试使用不存在的文件,没有读取权限的文件。太伤心了,我一直在努力,但什么都没有。 有人建议我试一试吗,谢谢unix shell ksh:if语句获胜';我不能同时执行这两部分,shell,unix,scripting,ksh,Shell,Unix,Scripting,Ksh,伙计们,我的if语句只是执行第一部分,而else永远不会执行,即使尝试使用不存在的文件,没有读取权限的文件。太伤心了,我一直在努力,但什么都没有。 有人建议我试一试吗,谢谢 #testing file to be read and display error messages: if [ -f "$file" ] then echo="Error: Nonexistent or irregular file. " break else echo Found fi if [ -r "
#testing file to be read and display error messages:
if [ -f "$file" ]
then
echo="Error: Nonexistent or irregular file. "
break
else
echo Found
fi
if [ -r "$file" ]
then
echo "No Reading access"
break
else
echo Reading Access
fi
为什么你有
break
语句,你在从什么开始中断?是否有一个你没有展示的环?另外,它“不存在”谢谢,我还不知道如何巧妙地编辑我的问题。:-)突出显示您的代码并按CTRL+K或按如下按钮-->{}
是的,有一个循环,但break语句也不会执行…:-(好的,如果-f
和-r
测试都通过,那么让真实的案例回显$file
是什么。这些信息将被证明对调试为什么else
子句从未被命中很有用。您也可以尝试在if语句之前设置file
,以确保它在循环中没有任何地方得到设置为实际存在的东西。
#testing file to be read and display error messages:
if [ -f "$file" ];then
echo "Error: Nonexistent or irregular file. "
else
echo Found
fi
if [ -r "$file" ];then
echo "No Reading access"
else
echo Reading Access
fi