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 语句的更多相关文章

  1. Linux之shell脚本for、while、case语句的高级用法

    1.case语句的用法: [root@ELK-chaofeng test]# cat test3.sh #!/bin/bash while true ;do read -p "please ...

  2. Linux shell脚本 (十二)case语句

    case语句 case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构. case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令.case ...

  3. shell 脚本 for,while,case 语句详解及案例

    ################for循环语句的结构#############使用for循环语句时,需要指定一个变量及可能的取值列表,针对每个不同的取值重复执行相同的命令序列,直到变量值用完退出循环. ...

  4. python技巧 switch case语句

    不同于C语言和SHELL,python中没有switch case语句,关于为什么没有,官方的解释是这样的 使用Python模拟实现的方法: def switch_if(fun, x, y):    ...

  5. shell脚本编程基础之case语句

    基础简介 脚本编程分为: 面向过程 选择结构:if语句,单分支.双分支.多分支:case语句 控制结构:顺序结构(默认) 循环结构:for.while.until 面向对象 case语句结构 case ...

  6. shell script 学习笔记-----if,for,while,case语句

    1.if内的判断条件为逻辑运算: 2.if内的判断条件为目录是否存在,文件是否存在,下图先检验目录/home/monster是否存在,然后再检测/home/monster中的file.txt文件是否存 ...

  7. (二)shell中case语句、程序传参、while

    2.2.6.1.case语句(1)shell中的case语句和C语言中的switch case语句作用一样,格式有差异(2)shell中的case语句天生没有break,也不需要break,和C语言中 ...

  8. linux bash shell中case语句的实例

    本文介绍下,在bash shell编程中,有关case语句的一个例子,学习下case语句的用法,有需要的朋友参考下. 本文转自:http://www.jbxue.com/article/13377.h ...

  9. shell的case语句简述(shell的流控制)

    shell流控制:http://www.cnblogs.com/yunjiaofeifei/archive/2012/06/12/2546208.html 1.if then else 语句 if t ...

随机推荐

  1. [zt]Which are the 10 algorithms every computer science student must implement at least once in life?

    More important than algorithms(just problems #$!%), the techniques/concepts residing at the base of ...

  2. extern c

    extern "C"的主要作用就是为了能够正确实现C++代码调用其他C语言代码.加上extern "C"后,会指示编译器这部分代码按C语言的进行编译,而不是C+ ...

  3. .NET使用ICSharpCode.SharpZipLib压缩/解压文件

    SharpZipLib是国外开源加压解压库,可以方便的对文件进行加压/解压 1.下载ICSharpCode.SharpZipLib.dll,并复制到bin目录下 http://www.icsharpc ...

  4. .NET中的属性

    1.What?什么是属性       属性是对字段的封装.当类中有了一个字段以后,为了控制这个字段对外的一些表现(例如可访问性,是只读?只写?或者对自读赋值做一些必要的验证等等)我们把这个字段私有化( ...

  5. minicom/kermit捕捉日志

    1.minicom捕捉日志 ctrl-A Z 命令窗口中有 Capture on/off......L   2.kermit捕捉日志 ctrl-\ C进入kermit命令行模式 log session ...

  6. TextField 限定只输入数字的方法

    func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementStri ...

  7. DBLINK 创建与小结

    1.DBLINK 的作用 当用户要跨本地数据库,访问另外一个数据库表中的数据时,本地数据库中必须创建了远程数据库的dblink,通过dblink本地数据库可以像访问本地数据库一样访问远程数据库表中的数 ...

  8. AppSetting ,connectionStrings配置节

    <appSettings> <!-- 当前使用的学校代码 --> <add key="DefaultCompanyID" value="cs ...

  9. Cassandra 计数器counter类型和它的限制

    文档基础 Cassandra 2.* CQL3.1 翻译多数来自这个文档 更新于2015年9月7日,最后有参考资料 作为Cassandra的一种类型之一,Counter类型算是限制最多的一个.Coun ...

  10. LevelDB:一个快速轻量级的key-value存储库(译)

    作者:Jeff Dean, Sanjay Ghemawat 原文:http://leveldb.googlecode.com/svn/trunk/doc/index.html 译者:phylips@b ...