| 查看: 461 | 回复: 0 | |||
[交流]
2016-01-26总结(算术展开以及循环)
|
|
算术展开 $ i=5 $ echo $((i++)) $i 5 6 $ echo $ ((++i)) $i 7 7 if-elif-else-fi语句 example #! /bin/sh echo "Is it morning? Please answer yes or no." read YES_OR_NO if [ "$YES_OR_NO" = "yes" ]; then echo "Good morning!" elif [ "$YES_OR_NO" = "no" ]; then echo "Good afternoon!" else echo "Sorry, $YES_OR_NO not recognized. Enter yes or no." exit 1 fi exit 0 test 命令 数值测试 eq 等于则为真 -ne 不等于则为真 -gt 大于则为真 -ge 大于等于则为真 -lt 小于则为真 -le 小于等于则为真 example #! /bin/sh num1=$1 num2=$2 if test $[num1] -eq $[num2] then echo 'The two numbers are equal!' else echo 'The two numbers are not equal!' fi 字符串测试 = 等于则为真 != 不相等则为真 -z 字符串 字符串长度伪则为真 -n 字符串 字符串长度不伪则为真 文件测试 -e 文件名 如果文件存在则为真 -r 文件名 如果文件存在且可读则为真 -w 文件名 如果文件存在且可写则为真 -x 文件名 如果文件存在且可执行则为真 -s 文件名 如果文件存在且至少有一个字符则为真 -d 文件名 如果文件存在且为目录则为真 -f 文件名 如果文件存在且为普通文件则为真 -c 文件名 如果文件存在且为字符型特殊文件则为真 -b 文件名 如果文件存在且为块特殊文件则为真 example #! /bin/sh cd script if test -e test_num11 then echo 'The file already exist' else echo 'The file does not exists!' fi example(-a 与 -o 或) #! /bin/sh cd script if test -e "test_num" -a -e "test_file" then echo 'both file exist' else echo 'haha' fi |
» 猜你喜欢
26年储能、电池方向博士申请
已经有1人回复
求调剂,本科吉大,一志愿华工339
已经有2人回复
物理化学论文润色/翻译怎么收费?
已经有286人回复
意大利博洛尼亚大学招聘研究助理2名(2D材料/锂离子与钠离子电池方向)
已经有1人回复
关于碳量子点抗菌的研究
已经有15人回复
南大化学调剂
已经有11人回复
0703调剂
已经有2人回复
1
已经有16人回复
0703 调剂
已经有4人回复
山西大学资源与环境工程研究所化工分离/环境功能材料小组招收2026年博士生
已经有2人回复














回复此楼