Linux_shell learning and linux_shell Learning

Source: Internet
Author: User

Linux_shell learning and linux_shell Learning
Use of test in shellThe test command is used to check whether a condition is true. It can be used to test values, symbols, and files.

1. Use of Values

-Eq equals-ne not equal to-gt greater than-ge greater than or equal to-lt less than true-le less than or equal to true
1 #! /Bin/bash2 read-p "enter two numbers: "num3 num43 if test $ num3-eq $ num44 then5 echo" two numbers are equal "6 else7 echo" two numbers are not equal "8 fi

 

2. String test = equals! = If the length of a string is not equal to-z, the length of a string is false. If the length of a string is not false, the value is true. file test-e file name if the file exists, it is true-r file name if the file exists and is readable, it is-w file name if the file exists and can be written, it is true-x file name if the file exists and can be executed true-s file name if the file exists and has at least one character, it is true-d file name. If the file exists and is a directory, it is true-f file name. If the file exists as a common file, it is true-c file name. if the file exists and is a special character file, it is true-B file name. If the file exists and is a special block file, it is true.
1 cd/root2 if test-e./xy3 then4 echo 'The file already exists! '5 else6 echo 'The file does not exists! '7 fi

 

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.