Setting Up a Bash Profile and Aliasing a Program

Understanding the bash environment and simple bash scripting can really speed up your neuroimaging work. While I am not an expert in scripting, I have learned a few tricks that can make life easier. If you are interested in learning simple shell scripting, especially as it applies to processing neuroimages, the great folks at FSL have a good intro here. I will not get into scripting in this post but I will introduce a couple tricks that will cut down on your time spent doing what could be repetitive tasks.

I’ll start with setting up a bash profile (again, this info in quite Mac-centric but some of the info will apply to Linux systems as well – with modifications).

In order to set up the command line so a program/script can be ‘called’ from anywhere in Terminal, open up a new Terminal window. You should be in your home directory but you could type cd and press Return (Enter) to make sure you are in the home directory. Once in this directory, if you do not have a .bash_profile file, you will need to create one. To check to see if you have a .bash_profile file, enter the command ls -a. This will show all files including the hidden files in your home directory. As you can see from the screenshot below I already have a .bash_profile file.

If you do not have one, the quickest way to create one is to enter the following command:

touch .bash_profile

This will create an empty file called .bash_profile. You can ls -a again to verify that it was created.

Now to edit this file. I prefer to use TextEdit on the Mac, I know many people prefer VIM or some other editor but I like TextEdit. To open the .bash_profile file type:

open -a TextEdit .bash_profile

The following screen opens up.

Now we are going to source a program so it can be run from anywhere in the structure of your filesystem (in this case I want to be able to run dcm2nii without typing in the whole path to the application. To do this I type the following:

alias dcm2nii=/Applications/mricronmac/dcm2nii

If your program is somewhere else, then type the path to it. Save this updated .bash_profile and open a new Terminal window or tab (it’s best just to restart Terminal if possible). You will now be able to simply type: dcm2nii and run the program (without having to type the whole path to dcm2nii or whatever other program or script you want to run).

If you noticed what is in my .bash_profile you will see how to set up FreeSurfer and FSL so they will work correctly. I’ll write about those a different time but you can use this as a reference for getting them set up the first time.

About Jared Tanner

I have a PhD in Clinical and Health Psychology with an emphasis in neuropsychology at the University of Florida. I previously studied at Brigham Young University. I am currently a Research Assistant Professor at the University of Florida. I spend the bulk of my research time dealing with structural magnetic resonance images of the brain. My specialty is with traditional structural MR images, such as T1-weighted and T2-weighted images, as well as diffusion weighted images. I also look at the cognitive and behavioral functioning of individuals with PD and older adults undergoing orthopedic surgery. Funding for the images came from NINDS K23NS060660 (awarded to Catherine Price, University of Florida). Brain images may not be used without my written permission (grant and software requirements).