A test condition to judge
Returns a 0 exit state if the expression is true, or a non-0 exit state if the expression is false. Test has an alternative syntax, which is easier to read by enclosing the expression with parentheses "[]".
1. string comparison operators: =;! =
* *) "=" Compares two strings, equals returns 0 eject state, unequal returns non 0 exit status
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/99/A5/wKioL1lKfzui-BJ7AAA3g4gO3rE273.png "title=" Screenshot from 2017-06-21 20-26-06.png "alt=" Wkiol1lkfzui-bj7aaa3g4go3re273.png "/>
**)“ ! = "Compares two strings, does not equal returns 0 exit status, equals returns non 0 exit status
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/99/A5/wKiom1lKhb6xPSdtAAA4mLURxRU428.png "title=" Screenshot from 2017-06-21 20-26-20.png "alt=" Wkiom1lkhb6xpsdtaaa4mlurxru428.png "/>
2, numeric comparison operator:
-EQ detects if two numbers are equal and returns ture
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/99/A5/wKioL1lKhjuQM2swAAAkqeBPORQ987.png "title=" Screenshot from 2017-06-21 20-26-39.png "alt=" Wkiol1lkhjuqm2swaaakqebporq987.png "/>
* *) Enter an IP to detect if the host is powered on and prompt the user to enter IP when no IP is entered
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/99/A6/wKiom1lKkr3hkx3HAABXxdkvvqk265.png "title=" Screenshot from 2017-06-21 20-46-26.png "alt=" Wkiom1lkkr3hkx3haabxxdkvvqk265.png "/>
-ne detects if two numbers are equal and is not equal returns True
-LT detects if the number on the left is less than the right and, if it is, returns true
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/99/A5/wKiom1lKh0XDvSwtAAA3j-9zbx0932.png "title=" Screenshot from 2017-06-21 20-30-15.png "alt=" Wkiom1lkh0xdvswtaaa3j-9zbx0932.png "/>
-le detects if the left number is less than or equal to the right, and returns true if yes
-GT detects if the number on the left is greater than the right and, if it is, returns true
-ge detects if the number on the left is greater than or equal to the number on the right, and returns true if yes
*) Enter two numbers and add these two numbers to determine if their results are greater than 10
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/99/A6/wKioL1lKkkbBGWmBAAB3ODqXFE4784.png "title=" Screenshot from 2017-06-21 20-55-38.png "alt=" Wkiol1lkkkbbgwmbaab3odqxfe4784.png "/>
3. File Status operators:
-B file detects if the files are block devices and returns true if yes
-C file detects if the files are character device files and, if so, returns True
-D file detects whether the files are directories and, if so, returns True
-F file detects whether the files are normal files (neither directories nor device files), and returns True if yes
-W file detection is writable
-X file to detect whether files are executable
-S file to detect if files are empty and not NULL to return True
-e file detects the existence of files and returns true if yes
-L file detects if the files are links and, if so, returns True
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/99/A6/wKiom1lKiX7juS9KAAA-j7N236E068.png "title=" Screenshot from 2017-06-21 20-32-39.png "alt=" Wkiom1lkix7jus9kaaa-j7n236e068.png "/>
* *) Enter a filename to show the status of the file
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/99/A6/wKioL1lKkejjxwwwAAFh_Ca0sS8257.png "title=" Screenshot from 2017-06-21 20-56-20.png "alt=" Wkiol1lkkejjxwwwaafh_ca0ss8257.png "/>
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/99/A6/wKiom1lKkUzyHby7AAC2xmjC4Ys828.png "title=" Screenshot from 2017-06-21 21-21-58.png "alt=" Wkiom1lkkuzyhby7aac2xmjc4ys828.png "/>
4. Logical operators,
! Nonzero if the expression is true, returns false, otherwise true
-O or operation, with an expression true returns True
-A with operation, two expressions are true to return true
&& returns True when the command is executed
|| Execute command when returned to False
Second, if statement
The IF command checks the exit value of the command or list after if. If the first command evaluates to True, then the list of commands after then is run until else. , if the evaluation of the first command is false nonzero, run the list of commands between the else and fi (reverse write if, mark the end of the If block)
Example:
* *) automatically establishes the user in the target file and adds the password Westos
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/99/A6/wKiom1lKjoSigWXUAAEHHyHgrrs690.png "title=" Screenshot from 2017-06-21 20-57-12.png "alt=" Wkiom1lkjosigwxuaaehhyhgrrs690.png "/>
Third, expect statement
Implementing an auto-answer script in the shell with EXPRCT
*) automatic answer to SSH remote connection problem
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/99/A6/wKioL1lKj7eTfVNHAAC851sjFW0572.png "title=" Screenshot from 2017-06-21 21-07-56.png "alt=" Wkiol1lkj7etfvnhaac851sjfw0572.png "/>
*) remotely connect to the host using the auto-answer script and fetch the host name of the host
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/99/A6/wKiom1lKkHrgPWDFAAEj9ZXwnEY826.png "title=" Screenshot from 2017-06-21 21-05-06.png "alt=" Wkiom1lkkhrgpwdfaaej9zxwney826.png "/>
IV. Environment variables
Shells and scripts use variables to store data, and some variables can be passed along with their content to child processes, which are called environment variables.
*) env display all environment variables
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/99/A6/wKiom1lKkUzyHby7AAC2xmjC4Ys828.png "title=" Screenshot from 2017-06-21 21-21-58.png "alt=" Wkiom1lkkuzyhby7aac2xmjc4ys828.png "/>
*) Use alias to define your own system commands and write commands to the. bashrc file for permanent entry
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/99/A6/wKiom1lKk0DQ7UtfAABaIjzNv2U288.png "title=" Screenshot from 2017-06-21 21-25-39.png "alt=" Wkiom1lkk0dq7utfaabaijznv2u288.png "/>
# #讲 "MV" command changed to "HH"
Shell script (ii)