12-03-2001
55,
0
Join Date: Jul 2001
Last Activity: 4 August 2012, 5:30 AM EDT
Location: Wales
Posts: 55
Thanks Given: 0
Thanked 0 Times in 0 Posts
BASH "if" switches
When I was trying to find these conditional tests, I was finding it very difficult to locate any of these.
Hopefully this list will help for BASH shell users.
Usage:
if [ switch variable ]
eg:
if [ -e "$filename" ]; then
do
something.....
done
where switch and variable are one of the following:
switch variable
-n <variable> tests for non-empty variable
-e <filename> test for existence of file
-L <filename> tests if file is a link to another file
-f <filename> tests if is a regular file
-z <variable> tests if variable is empty
-d <directory> tests for existence of directory
-eq used instead of = (equal)
-neq used instead of != (not equal)
-lt used instead of < (less than)
-gt used instead of > (greater than)
-ge used instead of >= (greater than or equal)
-le used instead of <= (less than or equal)
hope this helps somebody....