Monday, February 24, 2014

Some example of if statement - Shell scripting example

#!usr/bin/ksh
num1=20
num2=30
if [[ $num2 -gt $num1 ]]; then
    echo "The second value ${num2} is greater than the first value ${num1} ."
    exit 1
else
    echo "The sum of these number is `expr $num1 + $num2`"
    echo "Cool, enjoy !!!"
fi

-----------------------------------------------------------

if [ -d /opt/share ]
then
    /usr/bin/rmdir /opt/share 2>/dev/null
        if [ $? != "0" ]
        then
            /usr/bin/rm -r /opt/share 2>/dev/null
        fi
    /usr/bin/rm -rf /opt/share 2>/dev/null
fi
/usr/bin/mkdir -p /opt/share
/usr/bin/cp ~jay/notes/* /opt/share

-----------------------------------------------------------

if [ `whoami` != "root" ]
then
    exit 1
fi

-----------------------------------------------------------

No comments:

Post a Comment