문제

I am running an installation script to install Grails on new machines with GVM.

#!/bin/bash
set -e

source "/Users/mecca831/.gvm/bin/gvm-init.sh"

echo "Install grails"
gvm install grails 2.1.1

GVM returns 1 in this case, which breaks my script. However, the script works if set -e is removed. It returns 0 and the correct prompt will show up. Anyone run into the same problem trying to install Grails with GVM?

도움이 되었습니까?

해결책

Non-trivial scripts have to be specifically written to run with set -e.

gvm-init.sh has not been written to allow this, and breaks when it's enabled.

Consider for example this section:

GVM_DETECT_HTML="$(echo "$GVM_RESPONSE" | tr '[:upper:]' '[:lower:]' | grep 'html')"
if [[ -n "$GVM_DETECT_HTML" ]]; then
    ...

This isn't good or idiomatic bash code in anyway, but it works well enough by itself. It finds lines containing "html", and sticks them in the variable. Then it checks whether the variable is empty or not.

However, when you enable set -e, the script exits if the variable will be empty, before the script has a chance to look at it and account for that.

There's not really anything you can do about this, short of rewriting gvm-init.sh or set +e before you run any affected code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top