为配置用的Shell Script设置不同环境下的参数

2021-04-28  本文已影响0人  Lyudmilalala

写两个包含不同环境参数的脚本config.dev.shconfig.prod.sh

backend_git='backend-dev'
frontend_git='frontend-dev'
parser_port=5010
export backend_git frontend_git parser_git parser_port
backend_git='backend-prod'
frontend_git='frontend-prod'
parser_port=5040
export backend_git frontend_git parser_git parser_port

写一个处理逻辑的脚本,并在开始用source引入对应的环境参数脚本

source "config.$1.sh"
echo "my backend repo is $backend_git"
echo "my frontend repo is $frontend_git"
echo "my parser port is $parser_port"

运行时将环境作为第一个参数传入

$ sh call.sh dev
my backend repo is backend-dev
my frontend repo is frontend-dev
my parser port is 5010
$ sh call.sh prod
my backend repo is backend-prod
my frontend repo is frontend-prod
my parser port is 5040
上一篇 下一篇

猜你喜欢

热点阅读