linux shell program summary
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的更多相关文章
- linux shell 报错 Syntax error: Bad for loop variable
在linux下写了一个简单的shell,循环10次. test.sh #!/bin/bash ## ##循环10次 ## ; i<; i++)); do echo Good Morning ,t ...
- 面试题总结之Linux/Shell
Linux Linux cshrc文件作用 Linux如何起进程/查看进程/杀进程 Linux 文件755 代表什么权限 Linux辅助线程 Linux进程间通信方法 pipeline,msgq... ...
- 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 ...
- 老李分享:《Linux Shell脚本攻略》 要点(四)
老李分享:<Linux Shell脚本攻略> 要点(四) 1.IP地址的正则表达式: [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} 2. ...
- Linux Shell基础(下)
Linux Shell基础(下) 目录 一.shell特殊符号cut命令 二.cut.sort.wc.uniq命令 三.tee.tr.split命令 四.简易审计系统 五.fork, exec, so ...
- linux shell脚本之-变量极速入门与进阶(1)
1,如果创建shell脚本? 使用任意文本编辑软件,一般为vim,创建.sh结尾的文件,在文件的最开头用 #!/bin/bash 注明shell的类型 如: ghostwu@dev:~/linux/s ...
- linux shell 脚本攻略学习20--awk命令入门详解
awk生于1977年,创始人有三个,分别为 Alfred Aho,Peter Weinberger, 和 Brian Kernighan,名称源于三个创始人的姓的首字母. 作用:处理文本文件. awk ...
- 面试总结之Linux/Shell
Linux Linux cshrc文件作用 Linux如何起进程/查看进程/杀进程 Linux 文件755 代表什么权限 Linux辅助线程 Linux进程间通信方法 pipeline,msgq... ...
- 一个改动配置文件的linux shell script
不久以前,以前搜到一篇博客是读取配置文件的,http://www.cnblogs.com/bo083/archive/2012/11/19/2777076.html,用到如今,感觉十分方便.感谢作者. ...
随机推荐
- ASP.NET c# textbox 正则表达式 文本框只允许输入数字(验证控件RegularExpressionValidator )
<input type="text" name="test" onKeyUp="test1.value=(this.value=this.val ...
- iOS—如何申请苹果公司开发者账号流程详细图文介绍(包括邓白氏编码的申请方法详细介绍)
我们要申请开发者账号,首先就需要先注册一个苹果的apple id,然后再这个账号的基础上去继续,这个相信大家都知道 这是申请appleid的地址:https://appleid.apple.com/a ...
- 高流量站点NGINX与PHP-fpm配置优化(译)
使用Nginx搭配PHP已有7年的这份经历让我们学会如何为高流量站点优化NGINX和PHP-fpm配置. 以下正是这方面的一些提示和建议: 1. 将TCP切换为UNIX域套接字 UNIX域套接字相比T ...
- AD帐户操作C#示例代码(二)——检查密码将过期的用户
本文接着和大家分享AD帐户操作,这次开发一个简单的检查密码将过期用户的小工具. 首先,新建一个用户实体类,属性是我们要取的用户信息. public class UserInfo { /// <s ...
- unity 实现物体破碎效果的一些方法
游戏越来越接近现实的感觉,如果有一个真是的 虚拟现实设备,可能我们真的会感觉是在真实世界.场景的逼真是在渲染效果.角色AI.游戏逻辑.物理效果等等一起导致的结果.现在游戏越来越大,除了渲染,物理估计是 ...
- http statusCode(状态码) 200、300、400、500序列
201-206都表示服务器成功处理了请求的状态代码,说明网页可以正常访问. 200(成功) 服务器已成功处理了请求.通常,这表示服务器提供了请求的网页. 201(已创建) ...
- Codeforces Round #347 (Div. 2) (练习)
A: 题意:找到[a, b]的最大公约数: 思路:相同时为本身,不同时为1. 套路:碰到水题别想太多: 猜想:两个相邻数,必有一奇一偶,如果偶数有因子3或者其他,奇数可不可能有相同的呢? 枚举一些数后 ...
- C语言小练习三
题目要求: 定义一个二维数组保存 10个学生的5门课成绩,分别用函数实现:(1)input():输入每个学生的成绩:(2)output():输出每个学生的成绩:(3)aver_stu():计算并输出每 ...
- 代码规范、GitHub提交源码的标准 答题人-杨宇杰
1.格式与命名规范1.1 缩进 使用Tab缩进,而不是空格键1.2 换行 每行120字符 if,for,while语句只有单句时,如果该句可能引起阅读混淆,需要用" {"和&quo ...
- myBatis+SpringMVC+Maven整合
一.先创建表结构 二.使用generator通过表结构自动生成model和dao.mapper 使用步骤: 1.解压generator.rar文件 2.文件中的generator.xml文件需要进行修 ...