码迷,mamicode.com
首页 > 系统相关 > 详细

SHELL--待续

时间:2016-06-29 00:57:20      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

Bash变量

?变量=值

?引用方式为:$变量

[root@localhost Desktop]# HI="Hello,and welcome to $(hostname)."
[root@localhost Desktop]# echo $HI
Hello,and welcome to localhost.localdomain.
[root@localhost Desktop]#

 

?    &>       :重定向所有的输出

?    2>&1   :重定向STDERR到STDOUT

?    >         :重定向STDOUT

?    2>        :重定向STDERR

[root@localhost test]# ll *.sh *.txt > AAA
ls: cannot access *.txt: No such file or directory
[root@localhost test]# cat AAA
-rwxr--r--. 1 root root 158 Jun 28 06:36 test1.sh
-rwxrwxrwx. 1 root root  59 Jun 28 06:33 test.sh
[root@localhost test]# ll *.sh *.txt 2> BBB
-rwxr--r--. 1 root root 158 Jun 28 06:36 test1.sh
-rwxrwxrwx. 1 root root  59 Jun 28 06:33 test.sh
[root@localhost test]# cat BBB
ls: cannot access *.txt: No such file or directory
[root@localhost test]# ll *.sh *.txt &> CCC
[root@localhost test]# cat CCC
ls: cannot access *.txt: No such file or directory
-rwxr--r--. 1 root root 158 Jun 28 06:36 test1.sh
-rwxrwxrwx. 1 root root  59 Jun 28 06:33 test.sh

从文件重定向到标准输入:

[root@localhost test]# cat AAA 
-rwxr--r--. 1 root root 158 Jun 28 06:36 test1.sh
-rwxrwxrwx. 1 root root  59 Jun 28 06:33 test.sh
[root@localhost test]# cat AAA | tr a-z A-Z
-RWXR--R--. 1 ROOT ROOT 158 JUN 28 06:36 TEST1.SH
-RWXRWXRWX. 1 ROOT ROOT  59 JUN 28 06:33 TEST.SH
[root@localhost test]# tr a-z A-Z  <AAA
-RWXR--R--. 1 ROOT ROOT 158 JUN 28 06:36 TEST1.SH
-RWXRWXRWX. 1 ROOT ROOT  59 JUN 28 06:33 TEST.SH

for语句:

[root@localhost test]# cat for.sh 
#!/bin/bash
for NAME in joe jak sky
do 
   MESSAGE=hello world
   echo He name is $NAME.    "      $NAME say $MESSAGE !"
done
[root@localhost test]# ./for.sh 
He name is joe.       joe say hello world !
He name is jak.       jak say hello world !
He name is sky.       sky say hello world !
[root@localhost test]#

[root@localhost test]# cat for1.sh
#!/bin/bash
for num in $(seq 1 6)
do
   echo $num
done
[root@localhost test]# ./for1.sh
1
2
3
4
5
6
[root@localhost test]#

[root@localhost test]# cat if.sh 
#!/bin/bash
if ping -c1 -w2 128.0.0.1 &>/dev/null;                  then    echo network service is up !
   elif grep network /weihu.txt &>/dev/null;    then    echo network service is in maintenance !

else
   echo station is down !
fi
[root@localhost test]#

SHELL--待续

标签:

原文地址:http://www.cnblogs.com/skyfly0772/p/5625420.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!