标签:shell相关的用法
shell相关的用法
if用法
-q不输出结果,只做判断
[root@rs1 tmp]# if grep -q ‘^daixuan:‘ /etc/passwd; then echo "daixuan text" ;fi
,当/etcpasswd下包含daixuan,就输出daixuan test
case用法
[root@rs1 tmp]# vim case.sh
#/bin/bash read -p "Please input a number: " n m=$[$n%2] echo $m case $m in 1) echo "The number is jishu." ;; 0) echo " The number is oushu." ;; *) echo "It is not jishu or oushu." ;; esac
[root@rs1 tmp]# sh case.sh
Please input a number: 12
0
The number is oushu.
[root@rs1 tmp]# sh case.sh
Please input a number: 11
1
The number is jishu.
[root@rs1 tmp]# sh case.sh
Please input a number: abcdef
0
The number is oushu.
for用法
sed的使用
[root@rs1 tmp]# seq 1 10
1
2
3
4
5
6
7
8
9
10
[root@rs1 tmp]# seq 1 2 10
1
3
5
7
9
[root@rs1 tmp]# seq 10 -2 1
10
8
6
4
2
[root@rs1 tmp]# seq -w 1 10
01
02
03
04
05
06
07
08
09
10
[root@rs1 tmp]# vim for.sh
#/bin/bash for i in `seq 1 10`; do echo $i done
[root@rs1 tmp]# sh for.sh
本文出自 “daixuan” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1739414
标签:shell相关的用法
原文地址:http://daixuan.blog.51cto.com/5426657/1739414