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. js基础笔记

    <!DOCTYPE html><html lang="en"><head>        <meta charset="UTF- ...

  2. leetcode 24

    链表操作的,要注意标记头结点和边界问题. 代码如下: ListNode *swapPairs(ListNode *head) { if(head==NULL||head->next==NULL) ...

  3. HttpClient特性

    Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们再讨论),它不仅是客户端发送Http请求变得容易,而且 ...

  4. oracle 强杀进程

    在ORACLE数据库当中,有时候会使用ALTER SYSTEM KILL SESSION 'sid,serial#'杀掉一个会话进程,但是使用这个SQL语句杀掉会话后,数据库并不会立即释放掉相关的资源 ...

  5. 《你是我的小羊驼》游戏ios源码

    <ignore_js_op> <ignore_js_op> <ignore_js_op> <ignore_js_op>源码下载:http://code. ...

  6. 【PHP】金额数字转换成大写形式

    <?php /*将数字金额转成大写*/ function num_to_upper($num) { $d = array('零','壹','贰','叁','肆','伍','陆','柒','捌', ...

  7. MongoDB 3 + Windows 7 X64安装及配置

    注册windows服务,使MongoDB自动启动 1.使用系统管理员运行cmd C:\Users\admin> d: C:\Users\admin> cd "mongodb的安装 ...

  8. 正确使用stl map的erase方法

    先声明:下面的文章是针对windows的用法,因为std::map的erase函数的windows的实现版本是返回一个std::map的迭代器,但是STL标准里面的该函数的返回值确是: map.era ...

  9. win7修改软件【授权给…】后面的名称

    很简单,按下图打开注册表,修改: Ctrl+F分别搜索以下三个键值,搜到后修改为你想显示的名称即可即可. 1:UserName 2:RegisteredOrganazition 3:Registere ...

  10. 编写高质量代码改善C#程序的157个建议

    1.使用StringBuilder或者使用string.Format("{0}{1}{2}{3}", a, b, c, d)拼接字符串. 2.使用默认转型方法,比如使用类型内置的P ...