Search code examples
bashshellunixxterm

Close xterm -e command if no error


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


Solution

  • 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'"