Sunteți pe pagina 1din 4

Ch¬ng 2:

Bµi 2:
clear
echo " \********************************************\ "
echo "Today is:";date
echo "Hello $LOGNAME"
echo "Your current working directory: $PWD"
echo "Your home directory:$HOME"
echo -n "Please press anykey to finish:"
read a
echo -e "\t Thank you very much"
echo " \********************************************\ "
exit
bµi 3:
clear
echo "Cac phep toan co ban"
echo "Tham so ban da truyen vao la 2 so :$1 va $2"
echo "Tong $1+$2=`expr $1 + $2`"
echo "Hieu $1-$2=`expr $1 - $2`"
echo "Tich $1*$2=`expr $1 \* $2`"
echo "Thuong $1/$2=`expr $1 / $2`"
echo "So du :$1%$2=`expr $1 % $2`"
echo "--Shell script created by leo9x--"
bµi 4:
clear
echo "----Chuong trinh tao thu muc-----"
echo "Nhap ten thu muc can tao:"
read a
if mkdir $a
then
echo "Tao thu muc $a thanh cong"
else
echo "ko tao duoc thu muc $a"
fi
echo "--Shell script created by leo9x--"
bµi 5:
clear
echo "--chuong trinh thuc hien lenh gian tiep--"
echo "Lenh duoc yeu cau $1 $2 $3"
if $1 $2 $3
then
echo "thuc hien thanh cong"
else
echo "khong thuc hien duoc"
fi
echo "-----Shell scrit created by leo9x------"
Ch¬ng 3:
Bµi 2:
clear
echo "----Chuong trinh minh hoa vong lap for----"
echo -n "Nhap vao so dong can hien thi:"
read n
for (( i = 1; i <= $n ; i++ ))
do
for (( j = 1;j <= i; j++ ))
do
echo -n "*"
done
echo ""
done
for (( i = 1;i <= $n; i++ ))
do
for (( j = 1; j <= $n; j++ ))
do
echo -n "$j "
done
echo ""
done
echo "------Shell script created by leo9x--------"
bµi 3:
clear
echo "-------giai phuong trinh ax+b=0--------"
echo -n "nhap vao he so a:"
read a
echo -n "nhap vao he so b:"
read b
x=`expr $b % $a`
if [ $a -lt 0 ]
then
echo "Phuong trinh vo nghiem :( "
elif [ $x -ne 0 ]
then
echo " Nghiem cua phuong trinh la x=-$b/$a "
else
echo " Nghiem cua phuong trinh la x=`expr -$b / $a`"
fi
echo "----shell script created by leo9x-------"
bµi 4:
clear
echo "--------------Tinh tong---------------"
echo -n "Nhap vao 1 so:"
read n
t=0
for (( i = 1;i <= n;i++ ))
do
t=`expr $t + $i`
done
echo "Tong = $t"
echo "-----shell scirpt created by leo9x-----"
bµi 5:
clear
echo "------------Tinh bang cuu chuong------------"
chon=yes
while [ $chon = "yes" ]
do
echo -n "Moi ban nhap vao 1 so:"
read n
echo "bang cuu chuong cua $n:"
for (( i = 1;i <= 9;i++ ))
do
echo "$i x $n =`expr $i \* $n`"
done
echo -n "Ban co muon tiep tuc ko:"
kt=1
while [ $kt -eq 1 ]
do
read c
case $c in
"yes" )
chon=yes
kt=0;;
"no")
chon=no
echo "---------Shell script created by leo9x----------"
exit;;
*)
echo -n "Moi ban chon yes hoac no:"
kt=1;;
esac
done
done
bµi 6:
clear
echo "-------------tao nhieu thu muc------------"
echo -n "Nhap so thu muc muon tao:"
read n
for (( i = 1;i <= n;i++ ))
do
if mkdir user_$i
then
echo "thu muc user_$i da duoc tao thanh cong"
fi
done
echo "$n Thu muc da duoc tao.Go lenh ls de kiem tra"
echo "--------shell sript created by leo9x------"