Sie sind auf Seite 1von 3

Mathematical

>>ADD
Syntax: expr 20 + 10
Output: 30

>>SUB
Syntax: expr 20 - 10
Output: 10

>>MULTIPLY
Syntax: expr 20 \* 10
Output: 200

>>DIVISION
Syntax: expr 20 / 10
Output: 2

USING VARIABLE
>>ADD
Syntax:
NUM1=50
NUM2=30
echo $NUM1+$NUM2

Output: 80

>>Command: let

Syntax: let NUM3=NUM1+5


echo $NUM3
Output: 55

--------

>>>IF STATEMENT

Syntax:

MYNUM=100

if [$MYNUM -eq 200]


then
echo "MYNUM is equal to 200";
else
echo "MYNUM is NOT equal to 200"
fi

Output: MYNUM is NOT equal to 200

---------

>>>CHECK A SPECIFIC FOLDER EXISTS


if [ -d /root/testdir ]
then
echo "The folder exists."
else
echo "The folder does not exists."
fi

>>>CHECK A SPECIFIC FILE EXISTS

if [ -f /root/file1 ]
then
echo "The file1 exists."
else
echo "The file1 does not exists."
fi

>>>WHILE LOOP

myvar=1

while [ $myvar -le 10 ]


do
echo $myvar
myvar=$(( $myvar+1 ))
sleep 0.5
done

>>>CASE STATEMENT

echo "What is your favorite fruite?"

echo "1 - Mango"


echo "2 - Apple"
echo "3 - Jackfruite"
echo "4 - Orange"

read fruite;

case $fruite in
1)echo "You choose Mango";;
2)echo "You choose Apple";;
3)echo "You choose Jackfruite";;
4)echo "You choose Orange";;
*)echo "You choose something else";;
esac

echo "Choose your command?"

echo "1 - ls"


echo "2 - df -h"
echo "3 - du -sh"

read command;

case $command in
1)echo -e "You choose ls \n output is"
ls;;
2)echo -e "You choose df -h \n output is"
df -h;;
3)echo -e "You choose du -sh \n output is"
du -sh;;
*)echo -e "You choose something else";;
esac

----------------
row=1
for GETVALUE in net.ipv4.conf.all.accept_redirects
net.ipv4.conf.default.accept_redirects net.ipv4.conf.all.secure_redirects
net.ipv4.conf.default.secure_redirects
do
echo "Running process $row of 4"
krnl=`grep $GETVALUE /etc/sysctl.conf`
if [ "$krnl" == "$GETVALUE = 0" ]; then
echo -e "\t Protection was << DISABLED >>"
`sed -i s/"$GETVALUE = 0"/"$GETVALUE = 1"/g /etc/sysctl.conf`
echo -e "\t Protection is now << ENABLED >>"
elif [ "$krnl" == "" ]; then
echo -e "\t Protection << NOT FOUND >>"
`echo "$GETVALUE = 1" >> /etc/sysctl.conf`
echo -e "\t Protection is now << ENABLED >>"
else
echo -e "\t Protection is already << ENABLED >>"
fi
row=$(( $row+1 ))
done

Das könnte Ihnen auch gefallen