shell 参数¶
判断参数是否存在:
if test -z $1 then
xxxxx
fi
实例:
1#!/bin/sh
2#============说明===============
3# 此脚本是用于解决多个系统环境配置文件不同的问题
4#==============================
5
6usage() {
7 echo "-----------------用法-----------------------"
8 echo "参数1: octopus结点名"
9 echo "参数2: app, pvt, dev, pr。分别代表4个环境."
10 echo "其他:"
11 echo "\t1.配置文件会使用config/pr_octopus.config"
12 echo "\t2.会生成start.sh文件,可直接执行"
13 echo "-----------------实例-----------------------"
14 echo "sh> ./gen_start.sh octopus@10.140.2.17 pr"
15 echo "-----------------end-----------------------"
16}
17
18if test -z $1 | test -z $2; then
19 usage
20 exit
21fi
22
23if !(test $2 = "app" || test $2 = "pvt" || test $2 = "dev" || test $2 = "pr"); then
24 usage
25 exit
26fi
27
28
29cat gen_start.tpl | sed "s/{{NAME}}/$1/g" | sed "s/{{CONFIG}}/$2/g" > start.sh
30chmod +x start.sh