Answers:
您还可以使用大小写/切入bash
来执行此操作:
case "$MYAPP_ENV" in
PROD) SERVER_LOGIN="foobar123@prod.example.com" ;;
*) SERVER_LOGIN="foobar987@test.example.com" ;;
esac
或这种方法:
[ "$MYAPP_ENV" = PROD ] &&
SERVER_LOGIN=foobar123@prod.example.com ||
SERVER_LOGIN=foobar987@test.example.com
尝试:
[ condition ] && var=value_when_true || var=value_when_false
如果您的分配是数字分配,则可以使用bash
三元运算:
(( assign_condition ? value_when_true : value_when_false ))
true && false || echo "if this was ternary, this wouldn't be executed"