[shell基础]——if/for/while/until/case 语句
for语句
for loop in
do
echo $loop
done for loop in `seq `
do
echo $loop
done for loop in `ls /tmp`
do
echo $loop
done
while语句
while true
do
read -p "请输入你的密码:" passwd
if [ $passwd = "aixocm" ]
then
echo "密码输入正确,welcome"
break
else
echo "密码输入错误"
continue
fi
done
until语句
use=`df -lh | sed -n '/\/$/{p}' | awk '{print $5}' |sed 's/%//g'`
#如果/使用率满足小于80%的条件,则不执行循环,
#反之若/大于80%(即不满足条件),则执行循环
until [ $use -lt ]
do
echo "warning:your / user 80%" #向用户提出警告,你的/使用率已经大于或等于80%
exit
done
#而是执行循环外的这条,
#告诉用户,你的/使用率是多少,还少于80%
echo "now your / use $use%,less then 80%"
case语句
function directory()
{
[ -d $ ]
if [ $? -eq ]
then
echo "$1存在"
else
echo "$1不存在"
fi
} tput bold --->#加粗
echo "===查询菜单==="
tput sgr0 echo "1、查询/opt/aa 目录是否存在?"
echo "2、查询/opt/cc 目录是否存在?"
echo "3、查询/opt/dd 目录是否存在?"
read -p "你想查询啥?:" n
case $n in
)
directory /opt/aa
;;
)
directory /opt/cc
;;
)
directory /opt/dd
;;
*)
echo error
;;
esac
if语句
#if/else结构
if expression
then
command
else
command
fi
#if/elif/else结构
if expression1
then command
elif expression2
then command
elif expression3
then command
else command
fi
循环控制符:break和continue
break:忽略循环体中任何语句和条件的限制,强制退出当前循环
continue:跳过continue后面的语句,执行下一次循环,直到条件为真
[shell基础]——if/for/while/until/case 语句的更多相关文章
- Linux之shell脚本for、while、case语句的高级用法
1.case语句的用法: [root@ELK-chaofeng test]# cat test3.sh #!/bin/bash while true ;do read -p "please ...
- Linux shell脚本 (十二)case语句
case语句 case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构. case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令.case ...
- shell 脚本 for,while,case 语句详解及案例
################for循环语句的结构#############使用for循环语句时,需要指定一个变量及可能的取值列表,针对每个不同的取值重复执行相同的命令序列,直到变量值用完退出循环. ...
- python技巧 switch case语句
不同于C语言和SHELL,python中没有switch case语句,关于为什么没有,官方的解释是这样的 使用Python模拟实现的方法: def switch_if(fun, x, y): ...
- shell脚本编程基础之case语句
基础简介 脚本编程分为: 面向过程 选择结构:if语句,单分支.双分支.多分支:case语句 控制结构:顺序结构(默认) 循环结构:for.while.until 面向对象 case语句结构 case ...
- shell script 学习笔记-----if,for,while,case语句
1.if内的判断条件为逻辑运算: 2.if内的判断条件为目录是否存在,文件是否存在,下图先检验目录/home/monster是否存在,然后再检测/home/monster中的file.txt文件是否存 ...
- (二)shell中case语句、程序传参、while
2.2.6.1.case语句(1)shell中的case语句和C语言中的switch case语句作用一样,格式有差异(2)shell中的case语句天生没有break,也不需要break,和C语言中 ...
- linux bash shell中case语句的实例
本文介绍下,在bash shell编程中,有关case语句的一个例子,学习下case语句的用法,有需要的朋友参考下. 本文转自:http://www.jbxue.com/article/13377.h ...
- shell的case语句简述(shell的流控制)
shell流控制:http://www.cnblogs.com/yunjiaofeifei/archive/2012/06/12/2546208.html 1.if then else 语句 if t ...
随机推荐
- sorcketlog
正在运行的API有bug,不能var_dump进行调试,因为会影响client的调用. 将日志写到文件,查看也不方便,特别是带调用栈或大数据结构的文件日志,查看日志十分困难. 这时候用SocketLo ...
- solr5.5教程-tomcat布署(2)
tomcat 布署成功后,接下来就是使用了. 首先要创建一个core. 1.选择右侧菜单, Core Admin -> Add Core. 注意:name自己定义,instanceDir要填写上 ...
- angular $apply()以及$digest()讲解1
一些知名的批评和缺陷.他们都涉及到$digest loop(更新周期)中一个很常见的问题:如何在Angular之外更新$scope? 在哪调用 $apply? 更佳的做法是确保你是在$digest l ...
- oracle线程数更改
查看Oracle最大进程数: SQL> select count(*) from v$session #连接数,查看更多oracle数据库的疑问, 可点击cuug官网.http://www.cu ...
- vsftp快速配置
/etc/vsftpd/vsftpd.confanonymous_enable=YESlocal_enable=YESwrite_enable=YESlocal_umask=022dirmessage ...
- MFC创建对话框组件对应变量并进行设置值(VS2010)
m_path = strFolderPath; UpdateData(FALSE);
- c3p0配置xml
c3p0-config.xml <c3p0-config> <default-config> <property name="automaticTestTabl ...
- ubuntu 下安装极点五笔
安装完Ubuntu后先更新软件,我的Ubuntu的键盘输入方式系统是ibus 在终端中执行如下操作 sudo wget http://www.unicom-china.com/download/vis ...
- 禁止 PC端打开网页 进行跳转
try {var urlhash = window.location.hash;if (!urlhash.match("fromapp")){if ((navigator.user ...
- 【原】简述使用spark集群模式运行程序
本文前提是已经正确安装好scala,sbt以及spark了 简述将程序挂载到集群上运行的步骤: 1.构建sbt标准的项目工程结构: 其中: ~/build.sbt文件用来配置项目的基本信息(项目名 ...