shell中的条件语句
2015-06-25 22:47
483 查看
if-elif-else-fi语句
语法如下
if pipeline
[pipeline…]
then
statements-if-true-1
[elif pipeline
[pipeline…]
then
statements-if-true-2
…]
[else
statements-if-all-else-fails]
fi
case的语法为
case $varname in
pattern1)
statements
;;
pattern2)
statements
;;
*)
statements
;;
esac
case行尾必须为单词in,每一个模式必须以)结束
双分号;;表示命令序列结束
匹配模式中可以使用方括号表示一个连续的范围,如[0-9]
最后的*)表示默认模式。
if-elif-else-fi语句
语法如下
if pipeline
[pipeline…]
then
statements-if-true-1
[elif pipeline
[pipeline…]
then
statements-if-true-2
…]
[else
statements-if-all-else-fails]
fi
case的语法为
case $varname in
pattern1)
statements
;;
pattern2)
statements
;;
*)
statements
;;
esac
case行尾必须为单词in,每一个模式必须以)结束
双分号;;表示命令序列结束
匹配模式中可以使用方括号表示一个连续的范围,如[0-9]
最后的*)表示默认模式。
相关文章推荐
- linux shell脚本攻略 学习笔记1 -- 第一章 小试牛刀
- python调用shell命令之三大方法
- 用c实现的简单linux shell
- xshell十大技巧
- SSH 学习记录及在SSH模式下使用XShell连接服务器
- linux学习第二节 SHELL脚本语法
- Linux Shell之表达式
- shell学习二十六天----变量与算数
- git is not in the sudoers file.This incident will be reported
- shell 脚本编译c/c++
- Shell脚本:使用rsync备份文件/目录
- Shell基于模式匹配的字符串操作
- shell脚本基础知识(上)
- Linux下创建shell脚本文件
- bash审计
- 进入adb shell后
- CentOS6.5安装Tab增强版:bash-completion
- 'The WinRM Shell client cannot process the request' 错误, Exchange 2013 PowerShell
- shell 的理解及遇到的问题
- Shell中if的基本语法和常见判断用法