The test command is commonly used to check whether certain conditions are true.
Numerical test
-EQ: Detects whether two numbers are equal, equal returns True
-ne: Detects whether two numbers are equal, not equal returns True
-GT: Detects if the left number is greater than the right and returns true
-LT: Detects if the left number is less than the right and returns true
-ge: Detects if the left number is greater than or equal to the right, and returns True
-le: Detects if the left-hand number is less than or equal to the right, and returns True
String test
=: Detects whether two strings are equal, returns equal to Ture
! =: Detects whether two strings are equal, not equal returns True
-Z: Detects if string length is 0, 0 returns True
-N: Detects if string length is 0, not 0 returns True
File test
-E File: Detects if the files are present and returns true if yes
-R file: Detects if the files are present and readable, and returns true if yes
-W File: Detects if the file exists and is writable, and returns true if it is
-X File: Detects if the file exists and is executable and returns true if it is
-S file: detects if the file exists and has at least one character, and returns true if it is
-D File: Detects if the files are directories and returns true if yes
-F File: Detects if the files are normal files and returns true if yes
-C File: Detects if the files are character special files and returns True if yes
-B File: Detects if the file is a block special file and returns True if it is
Practice
Answer
Shell Programming-test Command (VI)