while循环

  语法1:

    while [ 条件 ]

do

    命令序列

    done

  语法2:

    while read -r line

    do

    命令序列

    done

(切记while和左中括号一定要有空格)

例子

 #!/bin/bash
j=
SUM=
while [ $j -lt ]
do
SUM=$((SUM+j))
j=$[j+]
done
echo $SUM

if判断语句

  语法1:

    if 条件

    then

      命令序列

    fi

  语法2:

    if 条件

    then

      条件序列

    else

      条件序列

    fi

  语法3:

    if 条件

    then

      条件序列

    elif 条件

    then

      条件序列

      elif 条件

    then

      条件序列

    else

      条件序列

    fi

例子

#!/bin/bash
if [ -d /tmp/123 ];then
echo "this is directory"
else
echo "this is not directory"
fi

  

case语句

  语法1:  

    case $变量名称  in

    条件1)

      命令序列

      ;;

    条件2)

      命令序列

      ;;

    条件3)

      命令序列

      ;;

    *)

      命令序列

    esac

  语法2:

    case $变量名称 in

    条件1|条件4)

      命令序列

      ;;

    条件2|条件5)

      命令序列

      ;;

    条件3|条件6)

      命令序列

      ;;

      *)

      命令序列

    esac

 #!/bin/bash
case $ in
top)
top
;;
free)
free
;;
df)
df
;;
*)
echo "no param"
esac

函数定义:

  语法1:

  方法名(){

    命令序列    

  }

  语法2:

  function 方法名{

    命令序列

  }

 #!/bin/bash
sum(){
echo $(($+$))
}
sum

linux shell基础编程2的更多相关文章

  1. 【Linux基础总结】Shell 基础编程

    Shell 基础编程 重启虚拟机遇到磁盘损坏如何解决 Shell编程中变量的声明.引用及作用域 Shell程序 概述 以文件形式存放批量的Linux命令集合,该文件能够被Shell解释执行,这种文件就 ...

  2. Linux shell脚本编程(三)

    Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真” ...

  3. Linux shell脚本编程(二)

    Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...

  4. Linux shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

  5. Linux Shell基础(下)

    Linux Shell基础(下) 目录 一.shell特殊符号cut命令 二.cut.sort.wc.uniq命令 三.tee.tr.split命令 四.简易审计系统 五.fork, exec, so ...

  6. Linux shell基础知识(上)

    Linux shell基础知识(上) 目录 一.shell介绍 二.命令历史 三.命令补全和别名 四.通配符 五.输入输出重定向 六.管道符和作业控制 七.shell变量 八.环境变量配置文件 九.b ...

  7. Linux Shell脚本编程--Linux特殊符号大全

    Linux Shell脚本编程--Linux特殊符号大全 linux_shell 特殊符号的介绍 2011

  8. linux shell 基础 使用日志与心得

    linux shell 基础 使用日志与心得 1.#!/bin/bash 第一行就出现#!/bin/bash是指此脚本使用/bin/bash来解释执行.其中,#!是一个特殊的表示符,其后,跟着解释此脚 ...

  9. Linux Shell脚本编程while语句

    Linux Shell脚本编程while语句案例 1,每隔3秒,打印一次系统负载 #!/bin/bash while truedo    uptime    sleep 3done 2,把监控结果保存 ...

随机推荐

  1. 单源最短路SPFA算法

    $huaji^{233……}$模板:洛谷 P3371 #include<iostream> #include<algorithm> #include<cstdio> ...

  2. OC语法

    ``` int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSString *S= ...

  3. plot over time

    先选择监测点 最后输出,由于所有数据都被输出,因此需要等待久一点 可以勾选需要的值,记得更换勾选变量后再次点击apply 最后的效果: 最后可以把数据写出来做后处理 输出后的数据:

  4. 关于cin 与 cout 的加速

    在用cin 与 cout 的时候 可以使用 ios::sync_with_stdio(); cin.tie(); cout.tie(); 这样在输入大数据的时候可以加快许多

  5. 在OnActionExecuted 获取请求参数的值(包含类类型)

    1.在OnActionExecuting里 获取请求参数的值 比较简单 /// <summary> /// 获取首参数的值 /// </summary> /// <par ...

  6. Oracle PL/SQL之WITH查询

    [转自] http://blog.csdn.net/t0nsha/article/details/6730855 为什么要用WITH? 1. 如果需要在一段复杂查询里多次应用同一个查询,用WITH可实 ...

  7. 【实战】Oracle注入总结

    小结: Union联合查询: order by 定字段 and 1=2 union select null,null..... from dual 然后一个一个去判断字段类型,方法如下 and 1=2 ...

  8. CNN Advanced

    from sys import path path.append('/home/ustcjing/models/tutorials/image/cifar10/') import cifar10,ci ...

  9. mysql把之前表单进行拆分

    今天有个任务是需要把之前的历史数据做一个清理. 原历史数据 很多电话号码是放到了一起.所以需要新建一个联系方式表.然后进行增加 新建表格如下: 然后再进行查询数据. SELECT a.uid,subs ...

  10. Unity GetComponentsInChildren<T>(true);

    using System.Collections; using System.Collections.Generic; using UnityEngine; public class GetCompo ...