3

I have tried to write a shell script to run multiple commands in multiple terminals, but I am not able to run the commands. I can only open multiple terminals.

This is written in a shell script file sitl.sh:

#!/bin/bash

gnome-terminal --working-directory=/home/mit/catkin_ws/  && roslaunch iq_sim iris.launch && rosrun iq_gnc square

gnome-terminal --working-directory=/home/mit/ardupilot/ArduCopter/

gnome-terminal --working-directory=/home/mit/catkin_ws/

gnome-terminal --working-directory=/home/mit/catkin_ws/   && roslaunch iq_sim lidar.launch

If I run this script, the commands are executing in the same terminal. If I terminate the first command, the next command is running, if I terminate the second command, third command is running. I need to run all commands at a same time. I need to run each command in each terminal window at a same time using single shell script command. Kindly help me to resolve this issue.

My aim of the output is, need to run multiple commands, commands should execute separately in each terminal at a same time, I don't need to terminate first command, so that my second command will work.

Please, help me friends to resolve my issue.

4
  • Why do you need then to run in more terminals? Why not put an "&" at the end of each and DETACH them from the terminal and then do a "tail -f {logfile}" on each terminal and then put whatever you want to see into that logfile in the script? That seems more logical to me
    – Rinzwind
    Sep 24, 2020 at 7:26
  • 1
    @Rinzwind. I need to run in more terminals because it's like I need to give inputs in each terminal after these commands are running.
    – Praveen
    Sep 24, 2020 at 9:56
  • Then it is going quickly towards a piece of software using "pipes". Example for python: python-course.eu/pipes.php In BASH you would use a script that you run on 2 or more terminals that reads from a file, where you store your input into that file for any of those terminals and let one of the other scripts read that file and act upon it. You pass information through a text file.
    – Rinzwind
    Sep 24, 2020 at 10:12
  • @Rinzwind. I need to give the input individually, I don't want to merge it, I just want to run separately using only one command in different terminals.
    – Praveen
    Sep 24, 2020 at 10:30

1 Answer 1

0

You should use option -e or -x to gnome-terminal. According to man gnome-terminal:

   -e, --command=STRING
             Execute the argument to this option inside the terminal.

   -x, --execute
             Execute  the  remainder of the command line inside the termi‐
             nal.
1
  • $ man bash | less -p Lists, hint, the word; background
    – Hannu
    Mar 6, 2022 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .