Shell Scripting If [ -f ./file ]

2020-08-10 07:42发布

I am learning shell Scripting on my own, and I was investigation how to do the If, and I didn’t understand an example that had:

if [ -f ./$NAME.tar ]; then
    //do something
else
    //something else

Now I did some experimenting, and I gave NAME the name of a file I had on my directory. When I executed without the -f, it was entering in the else condition, but with -f it enters the //do something condition So I presume -f is for file. Is this correct? I just couldn’t find information to confirm this.

标签: shell
1条回答
男人必须洒脱
2楼-- · 2020-08-10 07:53

From bash manual:

  -f file - True if file exists and is a regular file.

So yes, -f means file (./$NAME.tar in your case) exists and is a regular file (not a device file or a directory for example).

查看更多
登录 后发表回答