Thursday, May 3, 2012

bash if

The if constructs in bash is a convenient tool if you know how to use it

conditions are inside [ ], which is equivalent to test command

== and related are for strings

-gt -ne for numeric comparison

-a -o for and or

if [ -f /var/log/message ]; then echo "message exists"; fi

[ "$(whoami)" != 'root' ] && (echo you are using non-privileged account; exit 1)

test "$(whoami)" != 'root'  && (echo you are using non-privileged account; exit 1)

No comments:

Post a Comment