Scripts demonstrating the differences between string and integer comparisons
#!/bin/bash
# this script is a good starting place to start playing around w/ the differences
a="a b c"
if [ "$a" == "a b c" ]
then
echo equal
else
echo not equal
fi
if [ "$a" == "a b" ]
then
echo equal
else
echo not equal
fi
a="1"
b="2"
if [ $a -eq $b ]
then
echo equal
else
echo not equal
fi
if [ $a -ne $b ] && [ "$a" != "$b" ]
then
echo Not equal, either as strings or ints
fi
File test operators
#!/bin/bash
# test properties of a file
file="testfile"
if [ -e $file ]
then
echo file exists
else
echo file does not exist
fi
if [ -x $file ]
then
echo file is executable
fi
if [ -w $file ]
then
echo file is writeable
fi
if [ -r $file ]
then
echo file is readable
fi
CarcWiki: Documentation/LinuxCommandLine/Conditionals (last edited 2006-03-08 12:48:04 by BrianMuller)