shell 学习

将maven 项目里面的jar 包导出目录: 在项目里面执行:
mvn dependency:copy-dependencies -DoutputDirectory=lib 
shell 参数之间必有空格分开,变量申明不能有空格
while [ "$i" != "100" ]
i=$(($i+1))

  

#!/bin/sh
  case $1 in
        "one")
echo "Your choice is ONE"
 ;;
      "two")
echo "Your choice is TWO"
 ;;
esac

  

#!/bin/sh
read -p "Please input (Y/N): " yn
[ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK, continue" && exit 0
[ "$yn" == "N" -o "$yn" == "n" ] && echo "Oh, interrupt!" && exit 0
echo "I don't know what your choice is" && exit 0

  

#!/bin/sh
while [ "$yn" != "yes" -a "$yn" != "YES" ]
do
        read -p "please in put you process" yn
done
echo "you answer is r"

  

until [ "$yn" == "yes" -o "$yn" == "YES" ]
do
	read -p "Please input yes/YES to stop this program: " yn
done
echo "OK! you input the correct answer."

until [ "$yn" == "yes" -o "$yn" == "YES" ] 参数之间有空格不然会报 [: too many arguments错误

  

#!/bin/sh
i=0
s=0
while [ "$i" != "100" ]
do
        i=$(($i+1))
        s=$(($s+$i))
done
echo "the end of total is : $s"

  输出是:5050

for animal in dog cat elephant
 do
        echo "there are ${animal}"
done

  输出结果:

there are dog
there are cat
there are elephant

查看当前有哪些用户:

#!/bin/bash
users=$(cut -d ':' -f1 /etc/passwd)  
for username in $users               
do
        id $username
        finger $username
done

检查服务器是否通  

 

#!/bin/sh
network="192.168.1"              # 先定义一个网域的前面部分!
for sitenu in $(seq 1 100)       # seq 为 sequence(连续) 的缩写之意
do
	# 底下的程序在取得 ping 的回传值是正确的还是失败的!
        ping -c 1 -w 1 ${network}.${sitenu} &> /dev/null && result=0 || result=1
	# 开始显示结果是正确的启动 (UP) 还是错误的没有连通 (DOWN)
        if [ "$result" == 0 ]; then
                echo "Server ${network}.${sitenu} is UP."
        else
                echo "Server ${network}.${sitenu} is DOWN."
        fi
done

  

转载于:https://www.cnblogs.com/ptbx/p/5894795.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值