Reputation: 2256
I have the following shell script to open an xterm window and install a repo.
#!/bin/bash
REPO_NAME=$1
REPO_DIR=$2
REPO_URL=$3
REPO_BRANCH=$4
CLONE="git clone --recursive $REPO_URL $REPO_NAME"
DIR="cd $REPO_DIR"
CHECKOUT="git checkout $REPO_BRANCH"
COMMAND="$CLONE && $DIR && $CHECKOUT"
xterm -T $REPO_DIR -geometry 90x30 -e "$COMMAND"
What I want to do is close xterm if $COMMAND runs with no errors. If there is an error I want to keep the window open, how can I do this?
I am aware of the -hold parameter but this keeps the window open even if $COMMAND passes. I only want it to be open if it FAILS
Upvotes: 0
Views: 401
Reputation: 88756
I suggest:
xterm -T $REPO_DIR -geometry 90x30 -e "$COMMAND || read"
or
xterm -T $REPO_DIR -geometry 90x30 -e "$COMMAND || read -p 'Press return to close window'"
Upvotes: 1
Reputation: 723
You can use the $?
variable to get the exit status of the previous program. Most programs return 0 as exit code on success. You can test it with a simple if construction.
Upvotes: 0