#!/bin/bash option="$1" echo $1 if [ "$option" == "start" ]; then echo "start" elif [ "$option" == "stop" ]; then echo "stop" else echo "options start|stop" fi # 执行 nacos start
执行 nacos start
正确结果
1 2
start+start start
执行 nacos:
正确结果:
1
options start|stop
加入操作指令
1 2 3 4 5 6 7 8 9 10
#!/bin/bash option="$1" echo $1 if [ "$option" == "start" ]; then pwd elif [ "$option" == "stop" ]; then echo "stop" else echo "options start|stop" fi
执行 nacos start
正确结果
1 2
start /home/maxzhao/script
测试宏定义操作执行
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/bash option="$1" test_pwd="pw" echo $1+"$option" if [ "$option" == "start" ]; then "$test_pwd"d elif [ "$option" == "stop" ]; then echo "stop" else echo "options start|stop" fi
执行 nacos start
正确结果
1 2
start /home/maxzhao/script
写入操作脚本测试
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash local_addr="/home/maxzhao/soft/nacos/distribution/target/nacos-server-1.0.0/nacos/bin/" option="$1" echo $1+"$option" if [ "$option" == "start" ]; then sh "$local_addr"startup.sh -m standalone elif [ "$option" == "stop" ]; then echo "stop" else echo "options start|stop" fi
执行 nacos start
正确结果
1 2
start /home/maxzhao/script
正确执行
最后脚本
1 2 3 4 5 6 7 8 9 10
#!/bin/bash local_addr="/home/maxzhao/soft/nacos/distribution/target/nacos-server-1.0.0/nacos/bin/" option="$1" if [ "$option" == "start" ]; then nohup sh "$local_addr"startup.sh -m standalone & elif [ "$option" == "stop" ]; then sh "$local_addr"shutdown.sh else echo "options start|stop" fi