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. Windows phone 8 学习笔记(8) 定位地图导航(转)

    Windows phone 8 已经不使用自家的bing地图,新地图控件可以指定制图模式.视图等.bing地图的定位误差比较大,在模拟器中测试新地图貌似比较理想.本节主要讲解下位置服务以及新地图控件的 ...

  2. [my]_ubuntu12.10_/etc/apt/sources.list

    deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse deb-src http://mirror ...

  3. javaSE第二天

    第二天    7 1:关键字(掌握)    7 2:标识符(掌握)    7 (1)就是给类,接口,方法,变量等起名字的字符序列    7 (2)组成规则:    7 (3)注意事项:    8 (4 ...

  4. 一个学生分数表,用sql语句查询出各班级的前三名

    昨天去一家公司面试,被这道题难住了,哎,又失去一次好的机会. 回来 之后就再想这个问题 表结构及数据如下:

  5. 复杂的databinding接受Ilist作为数据源

    Combobox控件绑定数据源时,List<T>可以作为数据源,但是List<String,Object> 不存在,我们有时候需要用Dictionary<String,o ...

  6. 获取屏幕分辨率(C/C++)

    C/C++获取屏幕分辨率的方法 int main(int argc, char* argv[]) { // 需要添加头文件: // #include <Windows.h> system( ...

  7. ngx_http_upstream_module模块学习笔记

    ngx_http_upstream_module用于将多个服务器定义成服务器组,而由proxy_pass,fastcgi_pass等指令引用 (1)upstream name  {...} 定义一个后 ...

  8. KMP串匹配算法解析与优化

    朴素串匹配算法说明 串匹配算法最常用的情形是从一篇文档中查找指定文本.需要查找的文本叫做模式串,需要从中查找模式串的串暂且叫做查找串吧. 为了更好理解KMP算法,我们先这样看待一下朴素匹配算法吧.朴素 ...

  9. div左右布局

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <!DOCTYPE html> <html>     <head> ...

  10. ubuntu上搭建vsftpd且通过mysql来管理FTP账号

    参考文章:http://wiki.ubuntu.org.cn/Vsftpd%E5%92%8Cmysql%E9%85%8D%E7%BD%AE 请各位先按照这篇文章一步一步操作,我这里是记录一些其间遇到的 ...