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