Linux Shell脚本

直接上干货,干净又卫生啊兄弟们~

随便写了几个脚本,主要方便自己看吧

启用脚本

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

切片操作待更.....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值