{"id":22,"date":"2010-05-14T19:03:51","date_gmt":"2010-05-14T19:03:51","guid":{"rendered":"http:\/\/brainybehavior.com\/neuroimaging\/?p=22"},"modified":"2011-03-04T02:14:54","modified_gmt":"2011-03-04T02:14:54","slug":"bash-profile-alias-program","status":"publish","type":"post","link":"https:\/\/brainybehavior.com\/neuroimaging\/2010\/05\/bash-profile-alias-program\/","title":{"rendered":"Setting Up a Bash Profile and Aliasing a Program"},"content":{"rendered":"<p>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 <a href=\"http:\/\/www.fmrib.ox.ac.uk\/fslcourse\/lectures\/scripting\/s_0005.htm\">here<\/a>. 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.<\/p>\n<p>I&#8217;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 &#8211; with modifications).<\/p>\n<p>In order to set up the command line so a program\/script can be \u2018called\u2019 from anywhere in Terminal, open up a new Terminal window. You should be in your home directory but you could type <em>cd<\/em> and press <em>Return (Enter)<\/em> 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 <em>ls -a. <\/em>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.<\/p>\n<p><a href=\"http:\/\/brainybehavior.com\/neuroimaging\/wp-content\/uploads\/2010\/05\/Terminal-\u2014-bash-\u2014-175\u00d760.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-23\" title=\"Terminal \u2014 bash \u2014 175\u00d760\" src=\"http:\/\/brainybehavior.com\/neuroimaging\/wp-content\/uploads\/2010\/05\/Terminal-\u2014-bash-\u2014-175\u00d760.png\" alt=\"\" width=\"357\" height=\"327\" srcset=\"https:\/\/brainybehavior.com\/neuroimaging\/wp-content\/uploads\/2010\/05\/Terminal-\u2014-bash-\u2014-175\u00d760.png 357w, https:\/\/brainybehavior.com\/neuroimaging\/wp-content\/uploads\/2010\/05\/Terminal-\u2014-bash-\u2014-175\u00d760-300x274.png 300w\" sizes=\"(max-width: 357px) 100vw, 357px\" \/><\/a><\/p>\n<p>If you do not have one, the quickest way to create one is to enter the following command:<\/p>\n<p>touch .bash_profile<\/p>\n<p>This will create an empty file called .bash_profile. You can ls -a again to verify that it was created.<\/p>\n<p>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:<\/p>\n<p>open -a TextEdit .bash_profile<\/p>\n<p>The following screen opens up.<\/p>\n<p><a href=\"http:\/\/brainybehavior.com\/neuroimaging\/wp-content\/uploads\/2010\/05\/textedit.bash_profile.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-24\" title=\"textedit.bash_profile\" src=\"http:\/\/brainybehavior.com\/neuroimaging\/wp-content\/uploads\/2010\/05\/textedit.bash_profile.png\" alt=\"\" width=\"481\" height=\"305\" srcset=\"https:\/\/brainybehavior.com\/neuroimaging\/wp-content\/uploads\/2010\/05\/textedit.bash_profile.png 481w, https:\/\/brainybehavior.com\/neuroimaging\/wp-content\/uploads\/2010\/05\/textedit.bash_profile-300x190.png 300w\" sizes=\"(max-width: 481px) 100vw, 481px\" \/><\/a><\/p>\n<p>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:<\/p>\n<p>alias dcm2nii=\/Applications\/mricronmac\/dcm2nii<\/p>\n<p>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&#8217;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).<\/p>\n<p>If you noticed what is in my .bash_profile you will see how to set up <a href=\"http:\/\/surfer.nmr.mgh.harvard.edu\/\">FreeSurfer<\/a> and <a href=\"http:\/\/www.fmrib.ox.ac.uk\/fsl\/\">FSL<\/a> so they will work correctly. I&#8217;ll write about those a different time but you can use this as a reference for getting them set up the first time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/brainybehavior.com\/neuroimaging\/2010\/05\/bash-profile-alias-program\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":23,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[10,66,9],"_links":{"self":[{"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/posts\/22"}],"collection":[{"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":5,"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":26,"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/posts\/22\/revisions\/26"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/media\/23"}],"wp:attachment":[{"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brainybehavior.com\/neuroimaging\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}