前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[linux] shell脚本编程-xunsearch安装脚本学习

[linux] shell脚本编程-xunsearch安装脚本学习

作者头像
唯一Chat
发布2019-09-10 12:47:27
6030
发布2019-09-10 12:47:27
举报
文章被收录于专栏:陶士涵的菜地陶士涵的菜地

安装脚本setup.sh

代码语言:javascript
复制
#!/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.家目录的环境变量

代码语言:javascript
复制
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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-12-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档