Chinaunix首页 | 论坛 | 博客
  • 博客访问: 988967
  • 博文数量: 195
  • 博客积分: 4890
  • 博客等级: 上校
  • 技术积分: 2221
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-09 15:34
文章分类

全部博文(195)

文章存档

2014年(1)

2013年(8)

2012年(22)

2011年(9)

2010年(54)

2009年(101)

我的朋友

分类:

2010-07-26 11:06:30

判断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 
阅读(684) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-03-20 15:18:34

学习了,多谢楼主分享哦!也欢迎广大linux爱好者来我的论坛一起讨论arm哦!www.lt-net.cn