[linux] shell脚本编程-xunsearch安装脚本学习
2023-02-18 15:41:21 时间
安装脚本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
相关文章
- Jgit的使用笔记
- 利用Github Action实现Tornadofx/JavaFx打包
- 叹息!GitHub Trending 即将成为历史!
- 微软软了?开源社区讨论炸锅,GitHub CEO 亲自来答
- GitHub Trending 列表频现重复项,前后端都没去重?
- Photoshop Elements 2021版本软件安装教程(mac+windows全版本都有)
- (ps全版本)Photoshop 2020的安装与破解教程(mac+windows全版本都有)
- (ps全版本)Photoshop cc2018的安装与破解教程(mac+windows全版本,包括2023
- 环境搭建:Oracle GoldenGate 大数据迁移到 Redshift/Flat file/Flume/Kafka测试流程
- 每个开发人员都要掌握的:最小 Linux 基础课
- 来撸羊毛了!Windows 环境下 Hexo 博客搭建,并部署到 GitHub Pages
- 超实用!手把手入门 MongoDB:这些坑点请一定远离
- 【GitHub日报】22-10-09 zustand、neovim、webtorrent、express 等4款App今日上新
- 【GitHub日报】22-10-10 brew、minio、vite、seaweedfs、dbeaver 等8款App今日上新
- 【GitHub日报】22-10-11 cobra、grafana、vue、ToolJet、redwood 等13款App今日上新
- Photoshop 2018 下载及安装教程(mac+windows全版本都有,包括最新的2023)
- Photoshop 2017 下载及安装教程(mac+windows全版本都有,包括最新的2023)
- Photoshop 2020 下载及安装教程(mac+windows全版本都有,包括最新的2023)
- Photoshop 2023 资源免费下载(mac+windows全版本都有,包括最新的2023)
- 最新版本Photoshop CC2018软件安装教程(mac+windows全版本都有,包括2023