zsh - 测试 ./script.sh doit 测试不显示真实输出
问题描述
#!/usr/bin/env zsh
doit() {
if [[ "$1" = "start" ]]; then
for loc in $(cat all-doc); do
if ! screen -list | grep -q My-$loc; then
screen -dmS My-$loc /home/Server -f /home/$loc.cfg
fi
done
elif [[ "$1" = "stop" ]]; then
for loc in $(cat all-doc); do
if screen -list | grep -q My-$loc; then
pkill -f My-$loc;
fi
done
else
echo "Option: ERROR..."
fi
}
nothing() {
if [[ "$1" = "start" ]]; then
echo "Option: 1"
elif [[ "$1" = "stop" ]]; then
echo "Option: 2"
else
echo "Option: 3"
fi
}
case "$2" in
start)
"$1" "$2";
;;
stop)
"$1" "$2";
;;
restart)
restart;
;;
*)
echo "Usage: $0 {doit|nothing} {start|stop|restart}"
exit 1
;;
esac
exit 0
输出:
./script.sh:34> case test (start)
./script.sh:34> case test (stop)
./script.sh:34> case test (restart)
./script.sh:34> case test (*)
./script.sh:45> echo 'Usage: ./script.sh {start|stop|restart}'
sage: ./script.sh {start|stop|restart}
./script.sh:46> exit 1
此脚本用于启动和停止并重新启动我的服务器。如果 $2 与两个函数中的 "start" "stop" "restart" 不匹配,则必须调用else
但不起作用。好的问题是为什么./script.sh doit test
不叫
else
echo "Option: ERROR..."
whats the sulotion?有没有更好的方法来为 ./script.sh $1 $2 我的意思是 $1 get function 和 $2 get start|stop|restart 做一些事情?
解决方案
推荐阅读
- c++ - 为什么 switch 和 if 语句与转换运算符的行为不同?
- apache-spark - 自定义 /src/main/resources/log4j.properties 未在 Spark 2.2 中加载
- javascript - Js:解析 .mov 元数据
- c# - 防止在逗号分隔的字符串中替换已替换的字符串
- android - FusedLocationProviderClient api异常,同时申请位置更新坐标
- emacs - Emacs 单引号字符串中的通用模式被突出显示
- angular - .NET Core 2/Angular 5 图像压缩
- php - 我想在 Prestashop 中通过 id 获取产品,并列出它们
- ios - 呈现的 UIViewController 在 segue 动画后消失
- android - react-native-fcm android通知不起作用