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