I am new to LINUX operating system. I am using ROS (Robotic Operating System) where I type few commands in separate terminal windows for doing the setup.

ie Before I run my program, I have to do (each in separate terminal):

~$ roscore 

~$ rosrun nodelet nodelet standalone

~/Desktop/OpenCV$ source setup.bash 

~/Desktop/OpenCV$ rosrun pcl_tutorial
front_view_bag input:=/velodyne_points

rosbag play file2.bag

The above commands are a must before I can actually run my C++ program and it is to be in the above order, issued from the respective directories.

I am using Ubuntu 12.04.
Is it possible to write a program or something so that if I run that single program, all the above commands will be properly executed in separate terminals at the respective directories rather than manually executing them each time?


You can make a shell script, to do so, open a Terminal with Ctrl + Alt + T and type:

touch daily-script.sh

Now we need to edit this file contents

xdg-open daily-script.sh

Next copy paste the below code to your file:


cd $HOME
xterm -hold -e "roscore" &
xterm -hold -e "rosrun nodelet nodelet standalone velodyne_pointcloud/CloudNodelet" &
cd $HOME/Desktop/OpenC
xterm -hold -e "source setup.bash; rosrun pcl_tutorial front_view_bag input:=/velodyne_points" &
cd /media/BE8C6D3A8C6CEDF9/Users/KARTHICK/Desktop/project/ros_datas
xterm -hold -e "rosbag play file2.bag"

exit 0

Once you save the file open a Terminal and type:

chmod +x daily-script.sh

Finally your file is executable, to run it:


  • I did exactly as you said... and get a terminal window in which the first command roscore is being executed... when I do ctrl+C it closes and another window having second command opens... They are not executing simultaneously ...which is what I want as I mentioned in my question... the commands start a process which depends on the previous one...so the order is necessary and they are executed simultaneously in separate terminal windows normally. – KARTHIK Feb 22 '13 at 8:22
  • I tried the edited answer... Now the commands execute in separate terminals simultaneously as I wanted... But the fourth command is not executing... This command runs the executable for a program front_view_bag .The executable is located by doing source setup.bash in the ~/Desktop/OpenCV/ directory allowing all packages in this path to be found by ROS.. – KARTHIK Feb 22 '13 at 8:38
  • @KARTHIK I updated my post – efthialex Feb 22 '13 at 9:08
  • 1
    Thank you @efthialex...Its working now... Can you provide me some links to learn about shell scripts... – KARTHIK Feb 22 '13 at 9:31
  • Well I had bought a book called Pro Bash Programming: Scripting the Linux Shell (Expert's Voice in Linux). Publication Date: October 19, 2009 | ISBN-10: 1430219971 | ISBN-13: 978-1430219972. You can find this book on Amazon. Also google learn shell scripts and you will find some useful resources. – efthialex Feb 22 '13 at 9:46

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.