shell相关的用法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell相关的用法相关的知识,希望对你有一定的参考价值。
shell相关的用法
if用法
-q不输出结果,只做判断
[[email protected] tmp]# if grep -q ‘^daixuan:‘ /etc/passwd; then echo "daixuan text" ;fi
,当/etcpasswd下包含daixuan,就输出daixuan test
case用法
[[email protected] 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
[[email protected] tmp]# sh case.sh
Please input a number: 12
0
The number is oushu.
[[email protected] tmp]# sh case.sh
Please input a number: 11
1
The number is jishu.
[[email protected] tmp]# sh case.sh
Please input a number: abcdef
0
The number is oushu.
for用法
sed的使用
[[email protected] tmp]# seq 1 10
1
2
3
4
5
6
7
8
9
10
[[email protected] tmp]# seq 1 2 10
1
3
5
7
9
[[email protected] tmp]# seq 10 -2 1
10
8
6
4
2
[[email protected] tmp]# seq -w 1 10
01
02
03
04
05
06
07
08
09
10
[[email protected] tmp]# vim for.sh
#/bin/bash for i in `seq 1 10`; do echo $i done
[[email protected] tmp]# sh for.sh
本文出自 “daixuan” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1739414
以上是关于shell相关的用法的主要内容,如果未能解决你的问题,请参考以下文章