Speed up your Bash sessions with “alias”

Some of you probably already know about this, but I just discovered it and wanted to share.

Tired of typing in the same terminal commands all the time? Try this:

alias cy='ssh -Y jdh33@cyberstar.psu.edu'

Now when you type “cy” in the terminal, it automatically replaces it with the command you specify in quotes.

You can do this for each session, but even more helpful is to put these alias commands in your .bashrc file so that they are run whenever you start bash (the “rc” in “bashrc” stands for “run commands” … at least I think it does). If you’re using cygwin, this file will be located at C:\cygwin\home\(your username)\.bashrc. Open it in a text editor and put your alias commands somewhere in the middle. (On the cluster, your .bashrc file is located in your home directory, ~.)

Some useful possibilities:

  • On your computer, create aliases to log into different clusters (“cy” for cyberstar, “lx” for Lion-XO, etc.)
  • On the cluster, create aliases for common queue operations (“qme” for “qstat -u jdh33”, for example, which is a good idea I got from Ryan. Or “killall” for “qdel $(qselect -u jdh33)”. Pretty handy!)
  • Any long commands you find yourself repeating can be aliased! Just be careful not to overwrite any existing Linux commands when you do it.
You can check your current aliases at any time by running alias without any arguments.

That’s all, thanks for reading.


Programming Language Overview

This post details the programming languages commonly used in our group.  For each language, we have included installation instructions, suggested reading materials, and other notes.


Description Procedural
API Reference http://www.cplusplus.com/reference/clibrary/
Windows Installation MinGW (Blog post about installing this is here), Cygwin
Linux Installation sudo apt-get install gcc
  • Be cautious of string functions, many built-in C functions are unsafe
  • GNU GCC allows mixing Fortran and C/C++ object files (i.e., call Fortran method from C/C++)


Description Object Oriented
Tutorial http://www.cplusplus.com/doc/tutorial/
API Reference http://www.cplusplus.com/reference/
Windows Installation MinGW (Blog post about installing this is here), Cygwin
Linux Installation sudo apt-get install g++
  • The Boost libraries contain many reusable components


Description Object Oriented, Managed Memory
Tutorial http://docs.oracle.com/javase/tutorial/
API Reference http://docs.oracle.com/javase/6/docs/api/
Books Effective Java by Joshua Bloch
Windows Installation JDK 6
Linux Installation sudo apt-get install openjdk-6-jdk
  • Java is a verbose language, but the verbosity allows stronger type safety
  • Consider developing in Eclipse or NetBeans
  • Oracle recently released version 7, which is backwards-compatible with earlier versions


Description Object Oriented, Functional, Managed Memory
Tutorial http://docs.python.org/tutorial/index.html
API Reference http://docs.python.org/
Books Dive into Python by Mark Pilgrim
Windows Installation Python 2.7.2
Linux Installation sudo apt-get install python
  • There are two major versions of Python, 2.7 and 3.2.  They share similarities, but are not compatible
  • Use easy_install to quickly install packages
  • Use matplotlib for Matlab-like plotting

The Ternary Operator

The ternary operator (the question mark and colon in the expression a ? b: c) is a tricky one.  It’s use is relatively uncommon, but it’s present in many programming languages, and sometimes it drastically simplifies a conditional assignment.  I bring it up because it was in the first version I saw of the GAA objective function, and it was doing something it shouldn’t have been.  Before I took up the GAA problem, some of the work involved allowing a 3 percent constraint violation.  This was still present in the objective function when I got my hands on it, although we no longer wanted to allow a 3 percent constraint violation.

Here’s what it looked like:

constr[0] = CV_TOTAL > 0.03 ? CV_TOTAL : 0.0;

What it does is assign CV_TOTAL to constr[0] only if CV_TOTAL is greater than 0.03, and otherwise it assigns 0 to constr[0].  It works this way because in general, the expression a ? b : c evaluates to b if a is true, and to c if a is false. So writing d = a ? b : c is a shorthand way of saying, “assign b to d if a is true, and assign c to d if a is false.”  And what it does in this case is allow 3% constraint violation.

My advice: there’s nothing wrong with using the ternary operator, but don’t be stingy with your comments.  Writing it like this could save you a lot of time:

constr[0] = CV_TOTAL > 0.03 ? CV_TOTAL : 0.0; // allow 3% constraint violation!

Of the  languages that I’ve used, the ternary operator shows up in this form in C, C++, Java, and Ruby.