Main Menu

friends

Banner

Latest articles

Iphone on Linux
11/10/2009 | mad mad mod

Many Linux users would like to use their iPhone on Linux (synchronize mp3's, podcasts, appz, pictures, movies, ...). Because Apple does not have iTunes for Linux (its only available for Microsoft Win [ ... ]


List all open files with lsof
14/05/2010 | mad mad mod

"lsof" is a command which lists all open open files on a system. And because everything is a file in Unix (this includes pipes, network sockets, disk files and all other devices) it is a bit like a sw [ ... ]


Other Articles
Facebook MySpace Twitter Digg Delicious Stumbleupon Google Bookmarks 

Designed by:
SiteGround web hosting Joomla Templates
if then else in BASH - the basics E-mail
programming
If then else in bash is not very difficult. However, there is something that can cause problems:
Please note the spacing inside the brackets! It won't work without!
 

string comparison

simple example:



#!/bin/bash

MYVAR="hello"
if [ "$MYVAR" = "hello" ]; then
echo "true"
else
echo "false"
fi


 
 

integer comparison

 

A is equal B - a simple example: 

#!/bin/bash

A=1

B=2

if [ "$A" -eq "$B" ]; then
echo "$A is queal $B"
else
echo "$A is not equal $B"
fi



 

 

A is not equal B - a simple example:


#!/bin/bash

A=1

B=2

if [ "$A" -ne "$B" ]; then
echo "$A is not queal $B"
else
echo "$A is equal $B"
fi



 

 

A is greater than B - a simple example:


#!/bin/bash

A=2

B=1

if [ "$A" -gt "$B" ]; then
echo "$A is greater than $B"
else
echo "$A is not greater than $B"
fi



 

 

A is less than B - a simple example:


#!/bin/bash

A=1

B=2

if [ "$A" -lt "$B" ]; then
echo "$A is less than $B"
else
echo "$A is not less than $B"
fi



 

 

A is less than or equal to B - a simple example:

 

#!/bin/bash

A=1

B=2

if [ "$A" -le "$B" ]; then
echo "$A is less than or equal to $B"
else
echo "$A is greater than $B"
fi


Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

 
mad mad mod, Powered by Joomla! and designed by SiteGround web hosting