[linux] shell脚本编程-xunsearch安装脚本学习
2023-02-18 15:47:00 时间
安装脚本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
相关文章
- Git的简单的基本使用
- Android开发——导入github安卓项目源码
- 论文翻译:2021_A New Real-Time Noise Suppression Algorithm for Far-Field Speech Communication Based on Recurrent Neural Network
- linux系统下深度学习环境搭建和使用
- 解决github下载速度慢问题
- 论文翻译:1994_An Algorithm To Reconstruct Wideband Speech From Narrowband Speech Based On Codebook Mapping
- Git从入门到精通
- Linux指令学习
- MongoDB day04
- MongoDB day03
- MongoDB day02
- MongoDB day01
- php个人博客系统项目网站
- 基于thinkphp的服装女装男装衣服鞋子商城服装商城
- C/C++ Qt 信号自定义槽函数
- C/C++ Qt 常用数据结构
- C/C++ Qt 编译打包项目
- Linux 命令(231)—— let 命令(builtin)
- Linux 命令(232)—— bind 命令(builtin)
- Linux 命令(233)—— sum 命令