判断hpacucli rpm包是否安装,如果没有安装执行命令安装
#!/bin/bash
if [ ! -f /usr/sbin/hpacucli ]
then
echo 'hpacucli-7.85-18.linux.rpm is not install'
echo 'please install hpacucli-7.85-18.linux.rpm'
rpm -ivh hpacucli-7.85-18.linux.rpm > /dev/null 2>&1
sleep 10
echo 'hpacucli-7.85-18.linux.rpm install done'
fi
判断用户级别脚本
if [ ! `whoami` = root ]
then
echo -e "\e[31;1m ERROR:It is able to executed only by user ROOT.\e[0m"
exit 1
fi
do_continue.sh
#!/bin/bash
continue=n
echo -e "Do you want to continue?(y/n)"
read continue
if [ $continue != y ]
then
echo "conitune quit"
exit 0
fi
echo "OK... we will continue"
print_args.sh 打印出脚本参数
#!/bin/bash
#
# The shift command removes the argument nearest
# the command name and replaces it with the next one
#
while [ $# -ne 0 ] $# : 脚本执行的参数个数
do
echo $1
shift
done
判断输入的用户名是否存在
#!/bin/bash
echo -e "\e[40;32;1m please input user name: \e[0m"
read name
grep "$name" /etc/passwd >/dev/null 2>&1
if [ $? -eq 0 ]
then
echo "user $name exist"
exit 0
else
echo "user $name no exist"
exit 1
fi
一个简单的条件例程
测试条件之逻辑运算
-a And
-o Or
#!/bin/bash
echo -e "Are you ok ?"
read answer
if [ "$answer" = "Y" -o "$answer" = "y" ] 必须使用参数-o ,使用or出错
then
echo "I am ok"
elif [ "$answer" = "N" -o "$answer" = "n" ]
then
echo "I am no ok"
else
echo "what is your mean"
fi
显示所有命令行参数
$@和$*:依次显示你运行这个脚本时的所有参数
#!/bin/bash
for i in "$@" 或者 for i in "$*"
do
echo $i
done
exit 0
i=1
i=$[$1+1] $[] 表示进行算术运算
ehco $i
阅读(708) | 评论(1) | 转发(0) |