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. C语言打印最长字符串

    编程在一个已知的字符串中找最长单词,假定字符串中只含字母和空格,空格用来分隔不同单词. ]; printf("请输入字符串:"); fgets(p, , stdin); ; ; ; ...

  2. Java编程中“为了性能”尽量要做到的一些地方

    最近的机器内存又爆满了,除了新增机器内存外,还应该好好review一下我们的代码,有很多代码编写过于随意化,这些不好的习惯或对程序语言的不了解是应该好好打压打压了. 下面是参考网络资源总结的一些在Ja ...

  3. HTML5所有标签汇总

    来自lampbrother兄弟连HTML5与CSS3教程.<xmp> 结构标签:(块状元素) 有意义的div<article>     标记定义一篇文章<header&g ...

  4. 标题编辑 AndroidTagGroup

    地址: https://github.com/2dxgujun/AndroidTagGroup

  5. 【学习】JAVA的第一天(补)

    补上1024第一天的JAVA学习,也刚好是程序员节.今天学习了JAVA的一些历史和基础环境的配置,以及HelloWorld入门程序. JAVA体系:JAVAME(一些简单的移动端开发).JAVAEE( ...

  6. Swift基础语法(三)

    Array数组在swift中Array相当于oc中的NSMutableArray(变长数组) //1.定义数组 var numarr:Int[] = [,,,,]; var strarr:String ...

  7. apache安装mod_deflate配置支持gzip

    apache 配置支持gzip apache使用gzip压缩能够大幅提高网站访问速度并节省网络流量,在网页响应头信息中可以判断是否支持压缩. HTTP/1.1 200 OK Date: Wed, 14 ...

  8. ASP.NET Core 1.0 部署 HTTPS (.NET Framework 4.5.1)

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  9. node的事件模块应用(译)

    第一次接触Node.js时,就觉得他只不过是用javascript实现的服务端.但实际上他提供了许多浏览器端不具备的方法,比如EventEmitter类.我们在本文中来学习如何使用EventEmitt ...

  10. jQuery实现锚点平滑定位

    一般的锚点,就是点击一个按钮或者其他元素可以实现定位效果,当然可以使用锚点实现,但是这个不够美观,没有平滑的动画过渡效果,下面就通过代码实例介绍一下利用jquery实现平滑的定位效果. <!DO ...