linux shell条件与循环举例】的更多相关文章

1. if/else 语句 语法: if condition; then commands;elif condition; then commands;else commands;fi 示例:需求:脚本需要1个参数才能正确运行,而在脚本执行时,如果指定的参数个数不等于1,则shell脚本就应该打印出一个错误信息,告知用户指定的参数个数不对,然后结束脚本的执行.#!/bin/bashif [ $# -ne 1 ];then echo "Error! Arguments are not correc…
执行脚本: sh login.sh user,其中user为第一个参数 如下所示,如果用户‘user’登录,'who | grep "$1"'为true,until循环结束,程序继续执行,输出 “***** user has just logged in *****”信息. 如果用户‘user’没有登录,屏幕每隔60秒打印一次“ok”. $1表示程序的第一个参数 # login.sh 1 #!/bin/bash until who | grep "$1" >…
在linux的shell中 if 语句通过关系运算符判断表达式的真假来决定执行哪个分支.Shell 有三种 if ... else 语句: if ... fi 语句: if ... else ... fi 语句: if ... elif ... else ... fi 语句. 1) if ... else 语句 if ... else 语句的语法: if [ expression ] then Statement(s) to be executed if expression is true f…
一.if语句 if [expression] then elif[expression] then else fi 注 : expression前后要有空格:判断相等用 = 而不是 == : then可以另起一行,也可以与if同行,同行时要加';': 二.case模式 case值 in 模式1) command1 command2 command3 ;; 模式2) command1 command2 command3 ;; *) command1 command2 command3 ;; esa…
算术运算的条件判断 [] [[]]: -eq -ne -lt -le -gt -ge (( )):><>=<== [root@monitor ~]# if (( 2 == 3));then echo '123'; fi [root@monitor ~]# if (( 2 >= 3));then echo '123'; fi [root@monitor ~]# if (( 2 <= 3));then echo '123'; fi 123[root@monitor ~]#…
1.数字段形式for i in {1..10}do   echo $idone 2.详细列出(字符且项数不多)for File in 1 2 3 4 5 do     echo $File done 3.对存在的文件进行循环for shname in `ls *.sh`do           name=`echo "$shname" | awk -F. '{print $1}'`                     echo $namedone 4.查找循环(ls数据量太大的时候…
需求是统计某个业务的访问个数日志服务器上的目录结构是如下,搜索最近7天的指定关键字数据,并排重统计个数: drwxr-xr-x root root Nov : -- drwxr-xr-x root root Nov : -- drwxr-xr-x root root Nov : -- drwxr-xr-x root root Nov : -- drwxr-xr-x root root Nov : -- drwxr-xr-x root root Nov : -- drwxr-xr-x root r…
原语句: #!/bin/bash for test in I don't know if this'll work do echo "work:$test" done 结果: work:I work:dont know if thisll work:work 改成后语句: #!/bin/bash for test in I don\'t know if "this'll" work do echo "work:$test" done 结果: wo…
答:如下: ;i<100;i++)) do echo "i=${i}" done…
转http://blog.csdn.net/hittata/article/details/7042779 #/bin/bash   printf "*************************************\n"   echo " cat file whiel read line"   cat test.txt |while read line   do   echo $line;   done   printf "***********…