21

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.

4

1 回答 1

38

bash手册:

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

所以是的,-f意味着文件(./$NAME.tar在您的情况下)存在并且是常规文件(例如,不是设备文件或目录)。

于 2013-03-19T22:27:25.873 回答