#!/bin/bash nodejs_path=/data/myserver/yihao01-node-js cd /data/myserver if [ -d "$nodejs_path" ]; then cd $nodejs_path && git pull https://zuomiaomiao:zuomiaomiao123@gitlab.0easy.com/aiotcloud/yihao01-node-js.git else git clone https://zuomiaomiao:zuomiaomiao123@gitlab.0easy.com/aiotcloud/yihao01-node-js.git fi ipaddr='172.0.0.1' #ipaddr=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}') ipaddr=$(ip -4 address show | grep inet | grep -v 127.0.0 | awk '{print $2}' | cut -d'/' -f1) echo $ipaddr case "$ipaddr" in "192.168.0.16") env='dev' ;; "192.168.0.116") env='uat' ;; *) env='dev' ;; esac git clone https://gitlab.0easy.com/aiotcloud/yihao01-node-js.git cd $nodejs_path npm install -g npm npm install npm run $env
备注:变量赋值中间不能有空格,空格也是命令可以执行的