from:Sep 23 2016


mathematical operation:

floating number,bc calculator:

we can also use bc in shell scripts:


if - then - else

number comparison:

n1 -eq n2

n1 -ge n2

n1 -gt n2

n1 -le n2

n1 -lt n2

n1 -ne n2

if - then - elif, notice that the second elif won't be executed, though it's also right.


strings comarison:

str1 = str2

str1 != str2

str1 < str2

str1 /> str2

-n str1

-z str1


using file comparisons:

                  -d file    checks if file exists and is a dictory

-e file    checks if file exists

-f file     checks if file exists and is a file

-r file     checks if file exists and is readable

                 -s file     checks if file exists and is not empty

-w file    checks if file exists and is writable

-x file     checks if file exists and is executable

-o file     checks if file exists and is owned by the current user

-G file    checks if file exists and the default group is the same as the current user

file1 -nt file2   checks if file1 is newer than file2

file1 -ot file2   checks if file1 is older than file2


considering compound testing


working with advanced if-then features

((expression))

var++

var--

++var

--var

!              logical negation

~              bitwise negation

**             exponentiation

<<

>>

&

|

&&

||

notice the '++' of the screenshot.

it's writen of var++ not $var++


using double brackets

[[ expression ]]

the double bracket command provides advanced features for string comparisons---pattern matching.


Considering the case command:

case variable in

pattern1 | pattern2) command1;;

pattern3) command2;;

*) default commands;;

esac


The for command:


The while command:


The until command:

linux shell program summary的更多相关文章

  1. linux shell 报错 Syntax error: Bad for loop variable

    在linux下写了一个简单的shell,循环10次. test.sh #!/bin/bash ## ##循环10次 ## ; i<; i++)); do echo Good Morning ,t ...

  2. 面试题总结之Linux/Shell

    Linux Linux cshrc文件作用 Linux如何起进程/查看进程/杀进程 Linux 文件755 代表什么权限 Linux辅助线程 Linux进程间通信方法 pipeline,msgq... ...

  3. Bash For Loop Examples for Your Linux Shell Scripting--ref

    There are two types of bash for loops available. One using the “in” keyword with list of values, ano ...

  4. 老李分享:《Linux Shell脚本攻略》 要点(四)

    老李分享:<Linux Shell脚本攻略> 要点(四)   1.IP地址的正则表达式: [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} 2. ...

  5. Linux Shell基础(下)

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

  6. linux shell脚本之-变量极速入门与进阶(1)

    1,如果创建shell脚本? 使用任意文本编辑软件,一般为vim,创建.sh结尾的文件,在文件的最开头用 #!/bin/bash 注明shell的类型 如: ghostwu@dev:~/linux/s ...

  7. linux shell 脚本攻略学习20--awk命令入门详解

    awk生于1977年,创始人有三个,分别为 Alfred Aho,Peter Weinberger, 和 Brian Kernighan,名称源于三个创始人的姓的首字母. 作用:处理文本文件. awk ...

  8. 面试总结之Linux/Shell

    Linux Linux cshrc文件作用 Linux如何起进程/查看进程/杀进程 Linux 文件755 代表什么权限 Linux辅助线程 Linux进程间通信方法 pipeline,msgq... ...

  9. 一个改动配置文件的linux shell script

    不久以前,以前搜到一篇博客是读取配置文件的,http://www.cnblogs.com/bo083/archive/2012/11/19/2777076.html,用到如今,感觉十分方便.感谢作者. ...

随机推荐

  1. Xamarin +vs2015 Android 开发GPS loaction 返回 null 小结

    最近公司要开发android 所以研究了一下Xamarin  to android 中个GPS 废话不多说,说重点. 想获取手机上的gps信息必不可少的就是要使用 LocationManager Lo ...

  2. 检查Chunksum与Chunk Data之间的缓冲区发送到DataNode节点

    我们会看到左边"iOS Apps"下面有四个选项:"Certificates"."Identifiers"."Devices&qu ...

  3. 《UML大战需求分析》阅读笔记4

    流程分析利器之二,状态机图. 状态机图也可以叫状态图,也是用来分析流程的,之前的活动图的主体是事件的行为,而状态机图主要描述的是事件的状态. 开始:实心圆点: 结束:点加环:(与活动图一样) 状态:圆 ...

  4. ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节集合

    核心代码 using System; using System.Data; using System.Configuration; using System.Web; using System.Web ...

  5. gem sources --add http://ruby.taobao.org/

    gem sources  gem sources  gem sources --remove http://ruby.taobao.org/ gem sources --add http://ruby ...

  6. 词频统计web

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  7. 在c++这片神秘的大陆上

    在c++这片神秘的大陆上,有一个无往而不利的地下王国,据说其手段血腥残忍,却深得民心,因为,他们是侠,是剑胆琴心,诗肠酒骨的侠客,他们不知解决了多少疑难杂症,除去了多少问题漏洞,而他们的首领-> ...

  8. 编译系统中的 NFA/DFA算法理解

    1.问题概述 NFA 和 DFA浅析---要深入了解正则表达式,必须首先理解有穷自动机. 有穷自动机(Finite Automate)是用来模拟实物系统的数学模型,它包括如下五个部分: 有穷状态集St ...

  9. Java学习笔记四——运算符

    算术运算符 加减乘除(+.-.*./)就不说了. 求余运算符% 描述:第一个操作数除以第二个操作数,得到一个整除的结果后剩下的值就是余数 注意:求余预算的结果不一定总是整数,当操作数是浮点数时,结果可 ...

  10. 升级到win8.1右键响应慢

    网上很多资料都是在显卡上做文章,试了N次确定不是这个问题. 后来查到这个好用了.以管理员身份运行 下面代码保存bat即可 regsvr32 /u /s igfxpph.dll reg delete H ...