直接上干货,干净又卫生啊兄弟们~
随便写了几个脚本,主要方便自己看吧
启用脚本
bash xxx.sh 参数
for
#!bin/bash
s=0
for((i=1;i<=100;i++))
do
s=$[$s+$i]
done
echo $s
for i in "$*"
do
echo " for2 Like Python $1 "
done
for j in "$@"
do
echo " for2 Like Python $1 "
done
case
#!bin/bash
case $1 in
1)
touch 111.txt
echo "111.txt already created" >> 111.txt
;;
2)
touch 222.txt
echo "222.txt already created" >> 222.txt
;;
3)
touch 333.txt
echo "333.txt already created" >> 333.txt
;;
*)
rm -rf 111.txt 222.txt 333.txt
echo "All Files are Deleted :) "
;;
esac
while
#!bin/bash
s=0
i=1
while [ $i -le 100 ]
do
s=$[$s + $i]
i=$[$i + 1]
done
echo $s
if
#!bin/bash
if [ $1 = 1 ]
then
touch 111.txt
elif [ $1 = 2 ]
then
touch 222.txt
elif [ $1 = 3 ]
then
touch 333.txt
elif [ $1 > 3 ]
then
rm -rf 111.txt 222.txt 333.txt
fi
自定义函数
#!bin/bash
function sum(){
s=0
s=$[$1+$2]
echo $s
}
read -p "Input Num1: " P1
read -p "Input Num2: " P2
sum $P1 $P2
代码展示/删除脚本
#!bin/bash
case $1 in
if)
cat if.sh
;;
case)
cat case.sh
;;
for)
cat for.sh
;;
while)
cat while.sh
;;
del)
mr -rf if.sh
rm -rf case.sh
rm -rf for.sh
rm -rf while.sh
;;
*)
cat if.sh
cat case.sh
cat for.sh
cat while.sh
;;
esac