max pleaner max pleaner - 1 month ago 7
Linux Question

Rescue errors in terminal launched from script

I am using Ubuntu and made a short script on my Desktop. Double clicking it opens a terminal and starts my server.

This is all working fine except there's one problem. If there's an error raised in my server, the launched terminal immediately closes.

I want to keep the terminal open and show the error.

Here's my script:

#!/bin/bash

gnome-terminal -e '/bin/bash -c "cd ~/Desktop/browser_tester/; ./start.sh" '


I'm using the advice from this AskUbuntu answer to construct that command. I'm asking for a way to rescue errors inside the subprocess so that the
gnome_terminal
displays those errors and doesn't just exit.

Answer

You can check the exit status.

./start.sh || read

This will wait for a keypress if the command failed.