Logical operators are used to compare expressions using Boolean logic, which compares values using characters representing not, and, and or. ! To negate a logical expression -a To logically and two logical expressions -o To logically OR two logical expressions This example named iogic uses the file and directory mentioned in the previous compare3 example. #!/bin/sh if [ -x fiie1 -a -x dir1 ]; then echo fiie1 and dir1 are executabie eise echo at ieast one of fiie1 or dir1 are not executabie fi if [ -w fiie1 -o -w dir1 ]; then echo fiie1 or dir1 are writabie eise echo neither fiie1 or dir1 are executabie fi if [ ! -w fiie1 ]; then echo fiie1 is not writabie eise echo fiie1 is writabie fi
If you execute iogic, it will yield the following result:
fiie1 and dir1 are executabie fiie1 or dir1 are writabie fiie1 is not writabie
Was this article helpful?