shell编程——if语句【转载】】的更多相关文章

(2)shell编程——if语句_macg_新浪博客http://blog.sina.com.cn/s/blog_6151984a0100ekl6.html shell编程——if语句转载 if 语句格式if 条件then Commandelse Commandfi 别忘了这个结尾If语句忘了结尾fitest.sh: line 14: syntax error: unexpected end of fi if 的三种条件表达式ifcommandthen if 函数then 命令执行成功,等于返回…
shell编程中条件表达式的使用 if  条件then Commandelse Commandfi                              别忘了这个结尾 If语句忘了结尾fitest.sh: line 14: syntax error: unexpected end of fi if 的三种条件表达式 ifcommandthen if 函数then  命令执行成功,等于返回0 (比如grep ,找到匹配)执行失败,返回非0 (grep,没找到匹配) if [ expressi…
Shell编程基础 原作者 Leal:请参阅页面底部的编者列表. 授权许可: 创作共享署名协议 GNU 自由文档许可证 注意:本文仍然在持续的修订之中,且错漏之处可能较多.如果能够阅读英语的话,可以考虑试试较为完善的 Wooledge BashGuide.这个站点除了教程之外,还有一些类似“bash 百科”的内容.Bash 官方手册也是你的好朋友. 目录 1 从第一行开始 2 变量 2.1 变量赋值和引用 2.2 变量算术 3 Shell里的流程控制 3.1 if 语句 3.2 && 和…
本篇主要写一些shell脚本until语句的使用. 计算1-50的和 #!/bin/bash i=0 s=0 until [ $i -eq 51 ];do let s+=i;let i++ done echo $s [root@localhost ~]# vim sum.sh [root@localhost ~]# chmod +x sum.sh [root@localhost ~]# ./sum.sh 1275 为指定用户发送在线消息 #!/bin/bash username=$1 # 判断格…
本篇主要写一些shell脚本循环语句的使用. for 循环 指定次数 #!/bin/bash for ((i=1;i<=10;i++)) do echo $i done [root@localhost ~]# vim num.sh [root@localhost ~]# chmod +x num.sh [root@localhost ~]# ./num.sh 1 2 3 4 5 6 7 8 9 10 九九乘法口诀表 #!/bin/bash result=0 for ((i=1;i<=9;i++…
本篇主要写一些shell脚本case语句的使用. 字符判断 #!/bin/bash read -p "请输入一个字符:" char case $char in [a-z]|[A-Z]) echo "输入的是字母" ;; [0-9]) echo "输入的是数字" ;; *) echo "输入的是特殊符号" esac [root@localhost ~]# vim char.sh [root@localhost ~]# chmod…
本篇主要写一些shell脚本条件语句的使用. 条件测试 test 条件表达式 [ 条件表达式 ] 文件测试 -d:测试是否为目录(Directory). -e:测试文件或目录是否存在(Exist). -f:测试是否为文件(File). -r:测试当前用户是否有权限读取(Read). -w:测试当前用户是否有权限写入(Write). -x:测试是否设置有可执行权限(Excute). -nt:判断文件A是否比文件B新. -ot:判断文件A是否比文件B旧. -ef:判断两个文件是否为同一个文件,用来判…
if  条件then Commandelse Commandfi                              别忘了这个结尾 If语句忘了结尾fitest.sh: line 14: syntax error: unexpected end of fi if 的三种条件表达式 ifcommandthen if 函数then  命令执行成功,等于返回0 (比如grep ,找到匹配)执行失败,返回非0 (grep,没找到匹配) if [ expression_r_r_r  ]then …
if 语句格式 if  条件 then  Command else  Command fi                              别忘了这个结尾 If语句忘了结尾fi test.sh: line 14: syntax error: unexpected end of fi if 的三种条件表达式 if command then if  函数 then  命令执行成功,等于返回0 (比如grep ,找到匹配) 执行失败,返回非0 (grep,没找到匹配) if [ expres…
http://blog.csdn.net/dreamtdp/article/details/8048720 case语句适用于需要进行多重分支的应用情况. case分支语句的格式如下: case $变量名 in 模式1) 命令序列1 ;; 模式2) 命令序列2        ;; *) 默认执行的命令序列     ;; esac case语句结构特点如下: case行尾必须为单词“in”,每一个模式必须以右括号“)”结束. 双分号“;;”表示命令序列结束. 匹配模式中可是使用方括号表示一个连续的…