安装脚本setup.sh

#!/bin/sh
# FULL fast install/upgrade script
# See help message via `--help'
# $Id$

# self check
if ! test -d ./packages ; then
  echo "ERROR: you should run the script under its directory"
  echo "错误:您只能在脚本所在目录运行它"
  exit -1
fi

# get default prefix
if test -f $HOME/.xs_installed ; then
  def_prefix=`cat $HOME/.xs_installed`
elif test "$HOME" = "/" || test "$HOME" = "/root" ; then
  def_prefix=/usr/local/xunsearch
else
  def_prefix=$HOME/xunsearch
fi

if ! test -d ./packages ; then

1.shell脚本编程中的if判断配合test命令,判断目录是否存在

2.if判断格式如,写成一行 ,if test 条件;then 动作;else 动作;fi

3.判断条件相等用-eq 或者 =,不相等 -ne

4.if test -d $HOME ;then echo "$HOME is dir";else echo "$HOME is not dir";fi

 

$HOME

1.家目录的环境变量

 

i=0
while [ $i -lt $# ] ; do
  i=`expr $i + 1`
  eval arg=\$$i
  opt=`echo $arg | cut -d= -f1`
  val=`echo $arg | cut -d= -f2`
  case $opt in
        "--prefix")
          set_prefix="$val"
        ;;
        "--no-clean")
          set_no_clean=yes
        ;;
        # just for back compatibility
        "--clean")
          do_clean
          exit
        ;;
        "--force")
          if test "$val" != "no" ; then
        set_force=yes
      fi
        ;;
        "--enable-debug"|"--enable-memory-cache")
          xs_add_option="$xs_add_option $arg"
        ;;
        "--jobs")
          mk_add_option="$mk_add_option -j$val"
        ;;
        "--help")
      show_usage
      exit
        ;;
        *)
          echo "ERROR: unknown option '$arg'" >&2
          echo "" >&2
          show_usage
          exit -1
        ;;
  esac
done

 

while [ $i -lt $# ] ; do

1.while循环,当$i小与$#时,执行

2.while循环举例,注意空格

b=0;while [ $b -lt 5 ]; do b=`expr $b + 1`;echo $b; done

 

i=0

while [ $i -lt $# ] ; do

i=`expr $i + 1`

1.while循环 i=0;while [ $i -lt 5 ];do i=`expr $i + 1 `;echo $i;done

2.特殊变量$#是传递的参数个数

3.命令替换 ``

4.数学表达式工具 expr, echo `expr 1 + 1`

 

eval arg=\$$i

1.eval 把字符串变成变量

2.特殊变量 $1 $2,传递的参数

 

while test -z ""; do

1.test -z 判断字符串空,则为真 if test -z "";then echo 1;fi

2.test -n 判断字符串存在,则为真 if test -n "sss";then echo 1;fi