shell脚本学习指南[三](Arnold Robbins & Nelson H.F. Beebe著)

2019-09-23 09:42:11王冬梅

                fi

 
#最后循环test匹配位置改为:
  if test -"$testopt" "$file"

欧了,课后作业完成,安全性还没经验,有老师批改作业木有?

下边给了第二个脚本,是软件构建自动化,代码灰长长。。。这个打代码都码的头疼了,跳过吧,有兴趣童鞋自己搞定。我是不求甚解的先赶进度了,回来再搞。


#! /bin/sh -
# 在一台或多台构建主机上,并行构建一个或多个包
#
# 语法:
# build-all [ --? ]
#    [ --all "..." ]
#    [ --check "..." ]
#    [ --configure "..." ]
#    [ --environment "..." ]
#    [ --help ]
#    [ --logdirectory dir ]
#    [ --on "[user@]host[:dir][,envfile] ..." ]
#    [ --source "dir..." ]
#    [ --userhosts "file(s)" ]
#    [ --version ]
#    package(s)
#
# 可选用的初始化文件:
# $HOME/.build/directories list of source directories
# $HOME/.build/userhosts  list of [user@]host[:dir][,envfile]

IFS='
  '

PATH=/usr/local/bin:/bin:/usr/bin
export PATH

UMASK=002
umask $UMASK

build_one(){
#语法:
# build_one [user@]host[:build-directory][,envfile]
 arg="`eval echo $1`"

 userhost="`echo $arg | sed -e 's/:.*$//'`"

 user="`echo $userhost | sed -e s'/@.*$//'`"
 test "$user" = "$userhost" && user=$USER

 host="`echo $userhost | sed -e s'/^[^@]@//'`"

 envfile="`echo $arg | sed -e 's/^[^,]*,//'`"
 test "$envfile" = "$arg" && envfile=/dev/null

 builddir="`echo $arg | sed -e s'/^[^,]*,//'`"
 test "$builddir" = "$arg" && builddir=/tmp

 parbase=`basename $PARFILE`
 #NB:如果这些模式被更换过,则更新find_package()
 package="`echo $parbase |
  sed -e 's/[.]jar$//'
           -e 's/[.]tar[.]bz2$//'
           -e 's/[.]tar[.]gz$//'
           -e 's/[.]tar[.]Z$//'
           -e 's/[.]tar$//'
           -e 's/[.]taz$//'
           -e 's/[.]zip$//'`"
 #如果我们在远程主机上看不到包文件,则复制过去
 echo $SSH $SSHFLAGS $userhost "test -f $PARFILE"
 if $SSH $SSHFLAGS $userhost "test -f $PARFILE"
 then
  parbaselocal=$PARFLE
 else
  parbaselocal=$parbase
  echo $SCP $PARFILE $userhost:$builddir
  $SCP $PARFILE $userhost:$builddir