Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1691570
  • 博文数量: 362
  • 博客积分: 10587
  • 博客等级: 上将
  • 技术积分: 4098
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-10 18:15
文章分类

全部博文(362)

文章存档

2014年(1)

2013年(58)

2011年(115)

2010年(112)

2009年(76)

分类:

2010-09-26 16:56:22

例子 3-1. 代码块和I/O重定向

  1 #!/bin/bash
  2 # 从/etc/fstab中读行.
  3 
  4 File=/etc/fstab
  5 
  6 {
  7 read line1
  8 read line2
  9 } < $File
 10 
 11 echo "First line in $File is:"
 12 echo "$line1"
 13 echo
 14 echo "Second line in $File is:"
 15 echo "$line2"
 16 
 17 exit 0
 18 
 19 # 现在, 你怎么分析每行的分割域?
 20 # 小提示: 使用awk.


-----------------------------------------------------------------------------------

rpm文件安装检测


#!/bin/bash
# rpm-check.sh

#  Queries an rpm file for description, listing,
#+ and whether it can be installed.
#  Saves output to a file.
#  This script illustrates using a code block.

SUCCESS=0
E_NOARGS=65

if [ -z "$1" ]
then
  echo "Usage: `basename $0` rpm-file"
  exit $E_NOARGS
fi  

{ # Begin code block.
  echo
  echo "Archive Description:"
  rpm -qpi $1       # Query description.
  echo
  echo "Archive Listing:"
  rpm -qpl $1       # Query listing.
  echo
  rpm -i --test $1  # Query whether rpm file can be installed.
  if [ "$?" -eq $SUCCESS ]
  then
    echo "$1 can be installed."
  else
    echo "$1 cannot be installed."
  fi  
  echo              # End code block.
} > "$1.test"       # Redirects output of everything in block to file.

echo "Results of rpm test in file $1.test"

# See rpm man page for explanation of options.

exit 0

阅读(1099) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~