I'm trying to write a script which launches a Gnome terminal and runs multiple commands. It's used to log serial data through an USB and my final goal is to produce a script which opens several COM ports each on a different shell. All shells must execute:

sudo script /logs/deviceX.log
sudo picocom /dev/ttyUSB0 -b 115200 -p o | ts "%Y-%b-%d %H:%M:%S10"

and leave the shell running. I've verified the commands work ok when entered straight to a terminal so I tried creating an openPort script with the 2 commands and used

gnome-terminal -x bash -c "./openPort; exec bash"

but the terminal only executes the first command and not the second.

I then tried creating a separate script for each command and used

gnome-terminal -x bash -c "./openPort1; ./openPort2; exec bash"

but I still get the same result.

Is it simply a syntax problem or am I doing something completely wrong?


Launching gnome-terminal using -e instead of -x should work. In your case:

gnome-terminal -e "./openPort"

If you want to prevent the terminal window from closing, you need to make sure the script doesn't exit (for example by using sleep or by adding a "press for any key" prompt in the end, etc.). If you want an interactive shell after your script finishes, adding bash -i in the end should work.

  • Thanks that worked. There was also an issue with using script because of the way it works. Using sudo script -a -c 'sudo picocom /dev/ttyUSB0 -b 115200 -p o | ts "%Y-%b-%d %H:%M:%S10"' /logs/deviceX.log did the trick. ` – pavel Jul 19 '17 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.