for循环

for var in list;

do

  commands;#使用变量$var

done

example:

  for i in {a..z}; do actions; done;

后者

for((i=0;i<10;i++))

{

  commands;

}

while condition

do

  commands;

done

until循环

example:

x=0;

until [ $x -eq 9 ];

do

  let x++; echo $x;

done

if比较语句

if contions;

then

  commands;

if

else if和else语句

if condition;

then

  commands;

else if conditon;then

  commands;

else

  commands;

fi

简洁用法:

[ condition ] && action;

[ condition ] || action;

算数比较:
[ $var -eq 0 ]

[ $var -ne 0 ]

逻辑与和逻辑或

[ $var1 -ne 0 -a  $var2 -gt 2 ]

[ $var1 -ne 0 -o $var2 -gt 2 ]

example:

  

#!/bin/bash
#filename:compare.sh
fpath="/etc/passwd"
if [ -e $fpath ]; then
echo file exits;
else
echo does not exists;
fi

shell脚本6--循环,比较的更多相关文章

  1. shell脚本之循环语句与函数

    shell脚本之循环语句与函数 echo的用法: echo -n #表示不换行输出 echo -e #输出转义字符,将转义后的内容输出到屏幕上 转义字符: \n :换行,被输出的字符从"\n ...

  2. shell 脚本之循环使用 for while 详解

    任何一种编程语言中循环是比不可少的,当然 shell 脚本也少不了循环语句,包括 for 语句. while 语句.文中主要以实际用例来说明 for while 都有哪些常见的使用方法和技巧. 一.f ...

  3. shell脚本编程-循环(for、while、until)

    for命令格式:– list参数:迭代中要用的一系列值– 每个迭代中,变量var会包含列表中的当前值– do和done语句之间输入的命令可以是一条或多条标准的bash shell命令   1 2 3 ...

  4. shell脚本学习-循环

    跟着RUNOOB网站的教程学习的笔记 for循环 与其他编程语言类似,shell支持for循环. for循环一般格式为: for var in item1 item2 ... itemN do com ...

  5. Linux python3安装/shell脚本/if/循环/函数

    python3安装 安装过程 安装包: wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgztar -xvf Python-3.7 ...

  6. Shell脚本关于循环的一些总结

    不管是哪一门计算机语言,循环都是不可绕开的一个话题,Shell 当然也不是例外.下面总结一些 Shell 脚本里常用的循环相关的知识点,新手朋友可以参考. for 循环 Shell 脚本里最简单的循环 ...

  7. shell 脚本 - 关于循环的应用

    array=('Brand' 'BrandInfo' 'BrandBaojia' 'VehicleType' 'BrandBaoyang' 'Youhui' 'Config' \ 'Comment' ...

  8. shell脚本基础 循环机构

    循环结构 for循环格式一格式:for 变量 in 值1 值2 ........(值不一定是数字,可以是命令或者其他的)do 命令done [root@ceshiji ~]# vim a.sh #!/ ...

  9. Shell脚本中循环语句for,while,until用法

    循环语句: Bash Shell中主要提供了三种循环方式:for.while和until. 一.for循环 for循环的运作方式,是讲串行的元素意义取出,依序放入指定的变量中,然后重复执行含括的命令区 ...

  10. 自动化运维必须要学的Shell脚本之——循环语句(for、while和until循环)

    1. 循环前先了解echo的使用 1.1 echo -n 表示不换行输出 1.2 echo -e 输出转义字符,将转义后的内容输出到屏幕上 常见的转义字符有: 1.2.1 \b 相当于退格键 转义后相 ...

随机推荐

  1. VUE失去焦点提交修改值

    xxx.vue <input class="ml6 w85 bdr-6 bd-none text-center" type="text" v-model= ...

  2. 复习reactnative....

    import React, { Component } from 'react'; import { AppRegistry, Text, Image, View, TextInput, Scroll ...

  3. Html 文字排版

    文字竖立排版,方法一 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="v ...

  4. 设置git记住用户和密码

     git config --global credential.helper store

  5. JS onclick跳转

    onclick="javascript:window.location.href='URL'" onclick="location='URL'" onclick ...

  6. 萨塔尼亚的期末考试(fail)

    题解: 这题比较妙啊... 首先暴力自己算是找不出规律的 有一种直觉就是可以把式子变成{f[1]+...f[n]}+{f[2]+...+f[n]}+{f[3]+...+f[n]}... 然后看了题解发 ...

  7. Consumer is not subscribed to any topics or assigned any partitions

    版本: scala:2.11.8 spark:2.11 hbase:1.2.0-cdh5.14.0 报错信息: java.lang.IllegalStateException: Consumer is ...

  8. 带你了解zabbix整合ELK收集系统异常日志触发告警~

    今天来了解一下关于ELK的“L”-Logstash,没错,就是这个神奇小组件,我们都知道,它是ELK不可缺少的组件,完成了输入(input),过滤(fileter),output(输出)工作量,也是我 ...

  9. Kafka/Zookeeper集群的实现(二)

    [root@kafkazk1 ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.12/zookeeper-3.4.12. ...

  10. Codeforces 725E Too Much Money (看题解)

    Too Much Money 最关键的一点就是这个贪心可以在sqrt(n)级别算出答案. 因为最多有sqrt(n)个不同的数值加入. 我们可以发现最优肯定加入一个. 然后维护一个当前可以取的最大值, ...