首页 技术 正文
技术 2022年11月18日
0 收藏 718 点赞 4,808 浏览 997 个字

Shell编程(五)脚本语法${}: 数据“内容”删除,替换;{}: 列表

Shell编程(五)脚本语法

1. 条件测试: test

Shell编程(五)脚本语法

=~:正则匹配

Shell编程(五)脚本语法

Shell编程(五)脚本语法

2. if/then/elif/else/fi

#!/bin/bashecho "Is it ok? yes or no"read YES_OR_NOif [ "$YES_OR_NO" = "yes" ]; then
echo "is ok"
elif [ "$YES_OR_NO" = "no" ]; then
echo "is not ok"
else
echo "sorry"
exit
fi

Shell编程(五)脚本语法

3. case/esac

#!/bin/bashecho "is it morning"   read YES_OR_NO         case "$YES_OR_NO" in
yes|y|Yes|YES)
echo "good morning"
echo "good morning"
echo "good morning"
echo "good morning"
echo "good morning";;
[nN]*)
echo "good afternoon";;
*)
echo "sorry"
exit ;;
esac

Shell编程(五)脚本语法

4. for/do/done

#!/bin/bashfor Fruit in apple banana pear;do
echo "I like $Fruit"
done

Shell编程(五)脚本语法

#!/bin/bashfor read_parm in $@;do
echo $read_parm
done

Shell编程(五)脚本语法

5. while/do/done

#!/bin/bashecho "Enter passward: "
read key
while [ "$key" != "douzi" ];do
echo "Sorry, try again"
read key
done

Shell编程(五)脚本语法

#!/bin/bashCounter=
while [ "$Counter" -lt ];do
echo "Here we go again"
Counter=$(($Counter+))
done

Shell编程(五)脚本语法

  • 采用 i++
#!/bin/baship=115.239.210.27i=
while [ $i -le ]
do
ping -c1 $ip &>/dev/null
if [ $? -eq ];then
echo "$ip is up.."
fi
let i++ done

Shell编程(五)脚本语法

6. break和continue

#!/bin/bashcnt=
while [ $cnt -lt $# ];do
if [ $cnt -eq ];then
echo "this is break"
break
fi
cnt=$(($cnt+))
done

Shell编程(五)脚本语法

7. tee

功能:tee命令把结果输出标准输出,另一个副本输出到相应文件

Shell编程(五)脚本语法

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,948
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,474
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,287
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,102
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,734
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,769