Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to set up GNU Octave on my computer (Mac OS X 10.7.4). I am newbie in using Terminal and I need help to understand what the following script actually does:

if [ -f ~/.bashrc ];then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;. ~/.bashrc<br>
fi<br>
PATH=$PATH:/usr/local/bin<br>
BASH_ENV=~/.bashrc<br>
export BASH_ENV PATH<br>
export GNUTERM=aqua<br>
alias octave="/Applications/Octave.app/Contents/Resources/bin/octave"<br>
alias gnuplot="/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot"<br>

(taken from here: http://wikibox.stanford.edu/me112/index.php/Main/OctaveMatlabNotes)

So this script begins with the simple conditional if statement. I don't understand the conditional expression - what is -f and .bashrc? What the statement . ~/.bashrc actually does?

Then 2 variables are defined PATH and BASH_ENV. Why are they exported? Why GNUTERM=aqua is exported even if it's not defined anywhere?

All I need is a script that would allow me to run Octave by simply typing octave in the terminal. I don't need an alias for the gnu plot.

Thanks

share|improve this question

closed as too localized by Spiff, Daniel Beck, slhck, Canadian Luke, Tom Wijsman Jun 23 '12 at 18:14

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Try man bash. Come back with specific questions once you've tried to understand it. –  Daniel Beck Jun 22 '12 at 19:19
    
@DanielBeck I agree he should read the bash documentation, but sending a Terminal newbie to a man page in the terminal is torture. He'd have to learn how to navigate his default pager (more/less) first, which becomes a chicken-and-egg problem. Better to send him to a web-based copy first. –  Spiff Jun 22 '12 at 19:37
    
@Spiff Well, typing man bash into the web search box and feeling lucky works just as well. Or downloading the man pages app for iOS and browsing them on a phone. –  Daniel Beck Jun 22 '12 at 19:43
add comment

1 Answer

up vote 2 down vote accepted

[ -f ] tests if a file exists.

The tilde ~ is shell shorthand for your home/user directory. Files personal to you are stored there. ~/.bashrc, if it exists, is another bash startup file, in your home directory, that usually gets run when you start bash interactively (that is, when you're not just calling bash to execute a pre-existing bash script file). The example file you're looking at is probably meant to be a .profile, which is another shell startup script that typically only gets run when you're first logging into the system. If you have commands you only want run when you log in, you put them in ~/.profile. If you have commands that set up your interactive shell environment (like aliases that make commands easier to invoke), then you put them in your .bashrc. Since login shells are also interactive shells, you usually want your .profile to also load ("source") your .bashrc.

When your shell looks for commands to run, it consults the environment variable PATH. This line exports it so that other commands you invoke from the shell know where to find other commands. It also adds the directory /usr/local/bin to the PATH so that the shell and programs it runs also looks for commands there.

BASH_ENV defines what startup script bash should run if it's being invoked in a non-login, non-interactive situation. I guess it's being exported so that if you invoke a non-interactive bash instance (like to execute a pre-existing script file), it will still run your .bashrc. I don't usually want non-interactive shells running my .bashrc, so I would never define BASH_ENV the way it is defined in this example file you found.

GNUTERM is defined as being the string aqua. It's being defined and exported at the same time. Since you're on a Mac, which might not have XWindows (X11) installed, this is telling your GNUTerm/GNUPlot/GNUOctave environment what tool to run to draw your plots to the screen. Probably aquaterm, which you might want to make sure you've installed if you haven't already. I don't know about the whole Mac variants of the GNUOctave/GNUPlot/GNUterm/aquaterm ecosystem, so I can't advise you on the nitty-gritty details.

share|improve this answer
    
Great explanation! Thank you! –  Dimitri Jun 22 '12 at 22:47
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.