1

I'm working on Ubuntu OS, I want to make a single bash file which runs this code correctly as it shows in the screenshots.

Please notice that :

  • I want to launch two terminals in a single terminal window and the second set of codes in the second terminal should be launched after 5 seconds of the first set of codes in the first terminal.

  • I need the first set of codes to keep running (do not stop when starting the second terminal).*

Code:

cd catkin_ws
roscore
sleep 5
source devel/setup.bash
roslaunch hector _slam_launch tutorial.launch

Screenshots:

Terminal 1 Terminal 2

4
  • Please do not have pictures of text. Include all text in the body of the question.
    – David
    Apr 2, 2021 at 8:48
  • Either way it needs to be in the question not as a picture.
    – David
    Apr 2, 2021 at 9:48
  • I think the picture indeed is OK here because it to illustrate how the tabs should appear. However, you should embed it in the post itself. This forum has a function for that, which is powered by Imgur.
    – vanadium
    Apr 2, 2021 at 10:28
  • @Dark, any reason you changed your question to be like "aze aze zaeaz eaze zaeaze eaz e az"?
    – pLumo
    Apr 14, 2021 at 12:29

2 Answers 2

1

It used to work, and for now will still work with the following code:

gnome-terminal --tab -e "sh -c 'cd catkin_ws ; roscore'" \
               --tab -e "sh -c 'sleep 5; source devel/setup.bash ; roslaunch hector _slam_launch tutorial.launch'"

Issue is that the Gnome developers are considering dropping the -e ("execute") option, in favor of terminating your options with --, after which a command is supplied. They, however, forgot that this change makes that you only can provide a single command. It is not anymore possible to open Gnome Terminal automatically with multiple tabs containing different processes, for example each containing a different ssh session.

1
  • I usually test my answers, and running this from a script using the Alt+F2 prompt gives me neatly a new terminal window, "top" running in the first and the second waiting with a prompt, after ls was executed. Could not reproduce this with your applications, of course. However, I see that strangely, you refer to sudo in your comment. That was not there in your question. Obviously, you should not run gnome-terminal as root user.
    – vanadium
    Apr 5, 2021 at 10:45
0

You can create a terminal tab with gnome-terminal --tab command. Put the commands into a file and pass to bash as the --initfile parameter:

cd catkin_ws
tmpfile=$(mktemp /tmp/roslaunch-script.XXXXXX)
cat >$tmpfile <<EOF
sleep 5
source "$HOME"/.bashrc
source devel/setup.bash
roslaunch hector _slam_launch tutorial.launch
EOF
gnome-terminal --tab -- bash --init-file $tmpfile
roscore
rm $tmpfile
1
  • I can't test the entire script, but when I run this script from a gnome-terminal tab, roscore is started and a second tab is created which gives me bash: devel/setup.bash: No such file or directory error after 5 seconds.
    – mkayaalp
    Apr 5, 2021 at 12:21

You must log in to answer this question.

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