IMC!


Contents


Photos

 







Browsing around...
News  News Links  Links Blog  Blog Italiano  Español 
08 - Conditional expressions in the bash

 | 

In this section a list of all the conditional tests already discussed in the previous sections is shown and completed. The conditions are always written inside square brackets.

File operators
A series of operators exists in order to verify files conditions, according to the following syntax:

[ check_operator /etc/file_to_check]

These controls are:

OperatorMeaning
-d:Checks that the file is a directory
-e:Checks that the file exists
-f:Checks that the file is regular
-g:Checks that the SGID bit is set
-r:Checks that the file has the permissions for
reading for the user executing the script
-s:Checks that the file has a non zero dimension
-u:Checks that the SUID bit is set
-w:Checks that the file is writable

Number operators
Two numbers can be compared with the following tests. The variables must be written in the form:

"$variable_name"

The numerical tests are:

ControlMeaning
x -eq y true if x is equal to y
x -ne y true if x is not equal to y
x -gt y true if x is bigger than y
x -lt y true if x is smaller than y
x -ge y true if x is bigger than or equal to y
x -le y true if x is smaller than or equal to y

Strings controls
Two strings can be compared with the following tests:

"$variable_name"

These are the available scripts:

ControlMeaning
x = y true if x is equal to y
x != y true if x is equal to y
-n x true if x is not NULL or void
-z x true if x is NULL or void


Logical operators
The AND and OR logical operators can be used, according to the following syntax:

[ condition1 ] && [ condition2 ]

The logical operators are;
SymbolMeaning
& &AND
||OR

 | 






Fatal error: Call to undefined function sqlite_open() in /membri/giacobbe85/include/commenti.inc.php on line 324