conditions
if/then
then and fi statements are required, the space around the [ and ] symbols are also required:
if [ condition ]; then statements(s); fi
---------------
cat ifthen
if [ 2 -eq 2 ]; then
echo "ok"
else echo "not ok";
fi
$ bash ifthen
ok
------------------
$ if [ 2 -eq 2 ]; then echo "ok" else echo "not ok"; fi
ok else echo not ok
------------------
-r return true onlly if file exists and is readable
cat ift2
if [ ! -r "$1" ]; then
echo "error reading file"
else echo "ok"
fi
$ bash ift2 ifthen
ok
$ bash ift2 ifthen3
error reading file
then and fi statements are required, the space around the [ and ] symbols are also required:
if [ condition ]; then statements(s); fi
---------------
cat ifthen
if [ 2 -eq 2 ]; then
echo "ok"
else echo "not ok";
fi
$ bash ifthen
ok
------------------
$ if [ 2 -eq 2 ]; then echo "ok" else echo "not ok"; fi
ok else echo not ok
------------------
-r return true onlly if file exists and is readable
cat ift2
if [ ! -r "$1" ]; then
echo "error reading file"
else echo "ok"
fi
$ bash ift2 ifthen
ok
$ bash ift2 ifthen3
error reading file
Comments
Post a Comment