Use brackets in linux to determine conditions

Source: Internet
Author: User
In linux, brackets are used to determine the format # representing spaces. [# param1 # op # param2 #] is indispensable in the form of a comparison operator, which must be separated by spaces between the left and right sides of op. for example, if [#32 #] is a write method without spaces, the result is true. of course, the result is false. w...
In linux, brackets are used for condition determination. the format "#" represents space. [# param1 # op # param2 #] is indispensable in the form of a comparison operator, which must be separated by spaces between the left and right sides of op. for example, if [# "3" = "2" #] is missing spaces, the result is "true". of course, the result is actually "false ". the variables www.2cto.com should be enclosed in double quotation marks [#-z "$ name" #]. * ******************* name = "Jim" [$ name = "Jack"] # it will become [jim = "Jack"], an error occurs. * ******************* constants should be enclosed in double quotation marks or single quotation marks [# '1' #==#'10 '#]. better writing method: ******************************. each component in the brackets is separated by a space (which can be described as a base salary) B. variables are enclosed in double quotation marks ******* * ******************** Www.2cto.com parameter-B if the file exists and is a special block file, true-c file if the file exists and is a special character file, true-d file if the file exists and is a directory, true-e file if the file exists, true-f file if the file exists and is a rule file, true-g file if the file exists and the SGID bit value is set, true-h file. if the file exists and is a conforming link, true-k file if the file exists and the "sticky" bit value is set-p file if the file exists and is a named pipe, true-r file if the file exists and is readable, true-s file if the file exists and its size is greater than zero, true-u file if the file exists and the SUID bit is set, true-w file if the file exists and can be written, true-x file if the file exists and is executable, true-o file is true if the file exists and is owned by a valid user ID. -Z string if the string length is 0, true-n string if the string length is not 0, true string1 = string2 if the two strings are equal, true string1! = String2 if the two strings are not equal, it is true that www.2cto.com ************************************* * ******************** the numbers involved in the comparison must be converted to integers, do you have manual with this syntax? Int1-eq int2 if int1 is equal to int2, true int1-ne int2 if int1 is not equal to int2, true int1-lt int2 if int1 is less than int2, true int1-le int2 if int1 is smaller than or equal to int2, true int1-gt int2 if int1 is greater than int2, true int1-ge int2 if int1 is greater than or equal to int2, it is true ************************************** ********************! If expr is false, the composite expression is true. Expr can be any valid test expression expr1-a expr2 if both expr1 and expr2 are true, the entire formula is true expr1-o expr2 if expr1 and expr2 have one true, the entire formula is true www.2cto.com, in your example, do not mind ^_^ when the user inputs Y/y, the output is "OK, continue". when the user inputs N/n, the output is "Oh, interrupt!" When the user inputs other characters or is empty, the output "I don't know your command !"
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.