Visits

[+/-]
Today:
Yesterday:
Day before yesterday:
344
517
481

+36
This week:
Last week:
Week before last week:
2203
2962
3860

-898

Last month:
Month before last month:
8461
15650
24339

-8689

Visitor Data

IP ADDRESS
38.107.179.213
-
Location
United States
-
Browser
Unknown Browser
-
Operating System
Unknown Operating System


   
Add to: JBookmarks Add to: Bookmarks.cc Add to: Digg Add to: Reddit Add to: Upchuckr Add to: StumbleUpon Add to: Slashdot Add to: Blogmarks Add to: Technorati Add to: Newsvine Add to: Blinkbits Add to: Smarking Add to: Spurl Add to: Google Information
Conditional Expressions in BASH

if [ -e /etc/ntp.conf ]
then
echo "You have the ntp config file"
else
echo "You do not have the ntp config file"
fi

Now using an AND condition inside the [ ]. By the way, above, you
can put the "then" on the same line as the if "if [ -e /etc/ntp.conf ]; then"
as long as you use the ";".

if [ \( -e /etc/ntp.conf \) -a \( -e /etc/ntp/ntpservers \) ]
then
echo "You have ntp config and ntpservers"
elif [ -e /etc/ntp.conf ]; then
echo " You just have ntp.conf "
elif [ -e /etc/ntp/ntpservers ]; then
echo " You just have ntpservers "
else
echo " you have neither ntp.conf or ntpservers"
fi

A few things to note above. Else if statement is written as "elif", and when
dealing with "(" you will need to insert "\(". By the way "-o" can replace "-a"
and the "-o" is for OR condition. AND can be done as follows too.

if [ -e /etc/ntp.conf ] && [ -e /etc/ntp/ntpservers ]
then
echo "You have ntp config and ntpservers"
elif [ -e /etc/ntp.conf ]; then
echo " You just have ntp.conf "
elif [ -e /etc/ntp/ntpservers ]; then
echo " You just have ntpservers "
else
echo " you have neither ntp.conf or ntpservers"
fi

Conditional Expressions (files).


-b file      True if file exists and is a block file
-c file      True if file exists and is a character device file
-d file      True if file exists and is a directory
-e file      True if file exists
-f file      True if file exists and is a regular file
-g file      True if file exists and is set goup id
-G file      True if owned by the effective group ID

-k file      True if "sticky" bit is set and file exists
-L file      True if file exists and is a symbolic link
-n string    True if string is non-null

-O file      Ture if file exists and is owned by the effective user ID

-p file      True if file is a named pipe (FIFO)
-r file      True if file is readable
-s file      True if file has size > 0
-S file      True if file exists and is a socket

-t file      True if file is open and refers to a terminal.
-u file      True if setuid bit is set
-w file      True if file exists and is writeable
-x file      True if file executable
-x dir       True if directory can be searched

file1 -nt file2     True if file1 modification date newer than file2
file1 -ot file2     True if file1 modification date older than file2
file1 -ef file2     True if file1 and file2 have same inode

Conditional Expressions (Integers).

-lt  Less than
-le  Less than or equal
-eq  Equal
-ge  Greater than or equal
-gt  Greater than
-ne  Not equal

Example usage.

#!/bin/bash
{
while read num value; do
if [ $num -gt  2 ]; then
echo $value
fi
done
} < somefile


Conditional Expressions (Strings).

str1 = str2      str1 matches str2
str1 != str2     str1 does not matches str2
str1 < str2      str1 is less than str2
str1 >  str2     str1 is greater than str2
-n str1          str1 is not null (length greater than 0)
-z str1          str1 is null (las length 0)