摘要: shell编程系列5--数学运算 方法1 expr $num1 operator $num2 方法2 $(($num1 operator $num2)) expr操作符对照表1 操作符 含义 num1 | num2 num1不为空且非0,返回num1;否则返回num2 num1 & num2 num1不为空且非0,返回num1;否则返回0 num1 num2 ... 阅读全文
posted @ 2019-05-24 17:06 reblue520 阅读(524) 评论(0) 推荐(0) 编辑
摘要: shell编程系列4--有类型变量:字符串、只读类型、整数、数组 有类型变量总结: declare命令和typeset命令两者等价 declare、typeset命令都是用来定义变量类型的 declare命令参数总结 1.declare -r 将变量设置为只读类型 declare -r var="hello" var="world" # 变量默认可以修改 [root@es01 s... 阅读全文
posted @ 2019-05-24 16:48 reblue520 阅读(459) 评论(0) 推荐(0) 编辑
摘要: shell编程系列3--命令替换 命令替换 命令替换总结 方法1 `command` 方法2 $(command) 例子1: 获取系统的所有用户并输出 for循环能以空格、换行、tab键作为分隔符 [root@localhost shell]# cat example_1.sh #!/bin/bash # index=1 for user in `cat /etc/passwd ... 阅读全文
posted @ 2019-05-24 16:32 reblue520 阅读(311) 评论(0) 推荐(0) 编辑
摘要: shell编程系列2--字符串的处理 字符串的处理 1.计算字符串的长度 方法1 ${#string} 方法2 expr length "$string" (如果string中间有空格,必须加双引号) 例子: # 通过${#string}获取字符串长度 [root@localhost shell]# var1="hello world" [root@localhost shell]#... 阅读全文
posted @ 2019-05-24 10:07 reblue520 阅读(340) 评论(0) 推荐(0) 编辑
摘要: shell编程系列1--shell脚本中的变量替换 变量替换总结: 1、${变量#匹配规则} # 从头开始匹配,最短删除 2、${变量##匹配规则} # 从头开始匹配,最长删除(贪婪模式) 3、${变量%匹配规则} # 从尾开始匹配,最短删除 4、${变量%%匹配规则} # 从尾开始匹配,最长删除(贪婪模式) 5、${变量/旧字符串/新字符串} # 替换变量内... 阅读全文
posted @ 2019-05-24 10:00 reblue520 阅读(1567) 评论(0) 推荐(0) 编辑