Shell problem Summary (a): If combination judgment and determine whether the file exists

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.