Shell problem Summary, this series is I as a rookie in the process of solving problems to solve the process, I hope to record down to the new scholar help.
requirement : To resolve whether a file exists on the remote server
1, judge whether a file exists in general form is
If [-f filename] #这里有-E and-f differences, refer to link 1
The filename here is preferably an absolute path, which is especially important when determining whether a file exists in a remote server.
2, link remote server, use SSH
such as: if [SSH [email Protected]${ip}-f filename] in this form, it will be reported as the following error:
[: Too many arguments
3, improve, just change the above judgment to if ["ssh [email protected]${ip}-f filename"] is good.
Here are a few notable points to note:
1) If the "[" and "]" and the expression is a space;
2) in the 3rd above, the double quotation marks cannot be changed to single quotation marks, because the double quotation marks can retain the special function of the character, and the single quotation mark only as the character
In addition, I will not say a combination of if, see Link 2
There are other things you could do about the existence of a file in a remote server, see
REF:
81303258
Shell problem Summary (a): If combination judgment and determine whether the file exists