Monday, June 18, 2012

Ubuntu Shell scripting for ROS

Hi Guys,

  • Well, I have been using ROS (Robot Operating System: http://www.ros.org/wiki/) to develop my robotics packages and I have been syncing my packages between my laboratory and my home using Dropbox (https://www.dropbox.com/).
  • However, in my laboratory the PC is a 64 bit machine and at home I have a 32 bit machine. So, I have to build the packages from the beginning after syncing via Dropbox. When you have too many packages this is annoying.
  • Today I learned how to do this by a shell script.
  • I know it looks really childish but it does what I want.
  • Create a script file and enter the following into that file.
    • e.g. my_script.sh

#!/bin/bash
roscd my_pkg_one
make clean
rosmake my_pkg_one
roscd my_pkg_two
make clean
rosmake my_pkg_two


  • Go to the directory where your file is located and make it executable.
    • chmod +x my_script.sh 
  •  Run you script
    •  . ./my_script.sh
      the first dot makes sure the commands are run from the current shell and not from a subshell


  • If you want to run your script from anywhere you can add the script path to the PATH environment variable.
    • export PATH=$PATH:~/my_scripts     tothe end of your ~/.bashrc file. 
    • finally source your .bashrc file by
      • source ~/.bashrc

Sunday, June 17, 2012

Environment variables in Ubuntu

Hi guys,

  • I have been using the .bashrc file for long time but it was today that I understood clearly the syntax of export in .bashrc file.
  • Before, going into that let's get to know about the environment variables little bit more.
  • When we open a terminal session and type in a command like ls it is searched in the directories that are marked by the PATH variable.
  • PATH is an environment variable.
  • An environment variable is a variable that persists for the life of a terminal session. The applications running in that session can access these variables. A listing of all the environment variables can be obtained by
    • abc@def:~$ export
  • PATH environment variable has a special format. Use echo command to have a look at the variable:
    • abc@def:~$ echo $PATH
    • /usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:.
  • PATH variable is a : separated set of directories. All these directories will be searched when you execute a command in the terminal.
  • Let's give the PATH variable a different set of values
    • export PATH=/usr/bin:/usr/sbin
    • now, if we execute the ls command once again it will give an error because it no longer has /bin in the PATH variable.
  • Instead of changing or replacing the current set of directories in the PATH variable what you should do is to append it.
    • export PATH=$PATH:/new/path
    • echo $PATH  will now give you /usr/bin:/usr/sbin:/new/path
  • These changes, however, will be only valid to the current session. In order to making the changes permanent we can use a specific file called .bashrc file.
    • In Ubuntu (UNIX), files beginning with . are configuration files and are usually hidden.
    • To view these files use ls -a
  • The commands in .bashrc file get executed every time you start a new terminal
    • if you wish to have certain directories automatically added to PATH variable simply place those commands at the end of this file
 p.s.
  • If you are interested in knowing the full path of a binary like ls you can use the command which to find that out
    • e.g. abc@def:~$ which ls    will give you the result -> /bin/ls
      so, the executable ls is located in /bin directory


       

credit should go to the original contributor at http://www.cs.purdue.edu/homes/cs348/unix_path.html

Saturday, June 16, 2012

Grub Customizer for Ubuntu 11.04

Hey guys,

  • Some of you have already experienced that the program "startup manager" does not function in Ubuntu 11.04.
  • Use "Grub Customizer" instead.
  • Here are the steps:
    • sudo apt-add-repository ppa:danielrichter2007/grub-customizer
    • sudo apt-get update
    • sudo apt-get install grub-customizer