标签:yum tar path 大于等于 流程 size rest 开头 regular
流程控制之if语句
#!/bin/bash
var='/etc/init.d'
#var='/dev/sda'
if [ -d $var ]
then
echo "$var is directory"
elif [ -b $var ]
then
echo "$var is block"
elif [ -f $var ]
then
echo "$var is regular file"
else
echo 'unknow'
fi
向脚本传递参数
#test.sh
echo $0
echo $1
echo $2
echo $3
echo ${11}
echo '$$' $$
echo '$*' $*
echo '$@' $@
echo '$#' $#
echo '$?' $?
'''
测试:python test.sh 1 2 3 4 5 6 7 8 9 10 11
输出结果:
./test.sh
2
11
$$ 14312
$* 1 2 3 4 5 6 7 8 9 10 11
$@ 1 2 3 4 5 6 7 8 9 10 11
$# 11
$? 0
* $0 为运行的文件名
* $$ 为进程pid
* $* 为输入的所有的参数
* $@ 同$*
* $# 输入参数个数
* $? 上一条命令是否执行成功
'''
修改脚本,使其能接收调用者传来的参数
[root@MiWiFi-R3-srv ~]# cat test_file.sh
#!/bin/bash
if [ -d $1 ]
then
echo "$1 is directory"
elif [ -b $1 ]
then
echo "$1 is block"
elif [ -f $1 ]
then
echo "$1 is regular file"
else
echo 'unknown'
fi
[root@MiWiFi-R3-srv ~]# ./test_file.sh /etc/passwd
/etc/passwd is regular file
检测nginx是否启动,如果没启动,将其启动
#! /bin/bash
ps aux|grep nginx|grep -v grep
if [ $? -eq 1 ]
then
systemctl start nginx
fi
标签:yum tar path 大于等于 流程 size rest 开头 regular
原文地址:http://www.cnblogs.com/sama/p/7854900.html