I have an environment setup script where I want to alert the user as to what commands I'm executing (i.e. what is being installed). Using set -x
makes the output too cluttered, so I have a function successfully
that's called on commands that are important:
#!/bin/bash
trap "exit 1" TERM
export TOP_PID=$$
real_exit() {
echo -e "Goodbye :'("
kill -s TERM $TOP_PID
}
successfully() {
echo -e "$*"
$* || (echo -e "\nFailed. Check output and then retry, please." 1>&2 && real_exit)
}
For example, I can call successfully brew update
in my script, and if it fails, the user knows what command it fails on and the script stops.
However, my script is failing when I try to install Ruby/RVM:
successfully "curl -L https://get.rvm.io | bash -s stable --ruby"
The curl command works fine when I call it from the command line, yet it fails when the script calls it with the error:
curl -L https://get.rvm.io | bash -s stable --ruby
curl: option --ruby: is unknown
curl: try 'curl --help' or 'curl --manual' for more information