Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Typically we interact with the Linux operating system through what is referred to as a shell interpreter. A common interpreter is the Bourne Again Shell, which people call by the catchy name of Bash. Think of the relationship of the Shell and Linux like that between your steering wheel and your car. The steering wheel is not the car, just as Bash is not Linux. Rather the steering wheel lets you interact with your car in ways that make the car useful, just like typing commands into the Shell lets us make Linux do our bidding.

When one opens up a new Shell window (the Terminal utility on the Mac, for instance) a program is run in the background unbeknownst to us. This program is the Bash profile and is called “.bash_profile”. This is a script that includes Bash commands and is located in one’s home directory. Bash commands are simply those commands that one can type into the Bash Shell (all the stuff we normally use is fair game, like ls or cd, but there are ways to make the program more useful than printing the contents of one’s home directory to STDOUT, see below).

Note the period that starts the program name (“.bash_profile”). This means the file is invisible. If one types ls in one’s home directory any files that start in a period will be invisible. To see them, one must provide the -a flag to ls, like this, “ls -a”. These invisible files typically hold info that lets one customize some aspect of the computing experience.

If you don’t have a bash profile in your home directory, don’t worry. Simply make one using touch, like this: “touch .bash_profile”. For this to work properly, you need to be in your home directory, because that is where your computer expects to find the “.bash_profile” program. You can edit the bash profile by opening it with nano (type “nano .bash_profile” onto the command line).

Ok, so what useful things can we put in a Bash profile? The answer is anything one can think of that makes doing computing easier. Here are a few simple examples:

It is cumbersome to type lengthy commands over and over. Instead make a new command using an alias! Consider this option: alias interact="salloc --account=microbiome --time=1:45:00 --nodes=1 --ntasks-per-node=1 --cpus-per-task=1 --mem=2000”

If I type this command into my Bash profile, then the next time I open up a new Shell I can simply type “interact” on the command line and the computer interprets this as requesting an interactive session with the aforementioned specifications. Pretty handy.

One can modify environmental variables in one’s path as well. For instance, if one wants to change the $PATH then this can be specified in the Bash profile. See this link if you don’t know what a $PATH is: http://www.linfo.org/path_env_var.html

Lots and lots of recipes exist for putting useful things in a Bash profile. Do some googling and then get creative. You will likely find lots of convenient ways to improve your computing experience through modification of the Bash profile.

Note that if you edit your profile in Nano to save and exit the program see the instructions at the bottom of the editing window. Also, to use your spiffy new Bash profile you either need to open up a new Shell or source the program. To do the latter, simply type “source .bash_profile” (a path to the profile can be provided, one doesn’t have to be in one’s home directory to source the program. Source just means to run a program)

  • No labels