[英]How do I check to see if a file exists within a directory
I what to prompt a user to enter name of a file, read that into a variable, and use that variable to check if the valued enter is in fact a legimate file. 我要提示用户输入文件名,然后将其读入变量,然后使用该变量来检查输入的值是否实际上是合法文件。
How would I do this in a ksh script? 我将如何在ksh脚本中执行此操作? Thanks
谢谢
You know already how to read user input , here's the new part: 您已经知道如何阅读用户输入 ,这是新部分:
It's done with test(1) : 这是通过test(1)完成的 :
test -f $theFile && echo exists
It also has the alternate name [
which is most often used in if
or while
expressions: 它还具有备用名称
[
if
或while
表达式中最常用的名称:
if [ -f $theFile ]
then
echo exists
fi
Please refer to the above link (or alternatively the manual page). 请参考上面的链接(或手册页)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.