Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top