Книга: Fedora™ Unleashed, 2008 edition

Logical Operators

Logical Operators

Logical operators are used to compare expressions using Boolean logic, which compares values by 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 logic uses the file and directory mentioned in the previous compare3 example:

#!/bin/sh
if [ -x file1 -a -x dir1 ]; then
 echo file1 and dir1 are executable
else
 echo at least one of file1 or dir1 are not executable
fi
if [ -w file1 -o -w dir1 ]; then
 echo file1 or dir1 are writable
else
 echo neither file1 or dir1 are executable
fi
if [ ! -w file1 ]; then
 echo file1 is not writable
else
 echo file1 is writable
fi

If you execute logic, it yields the following result:

file1 and dir1 are executable
file1 or dir1 are writable
file1 is not writable

Оглавление книги

Оглавление статьи/книги

Генерация: 0.696. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз