TLDR: have to define an alias/variable using the export command, I can't use the full path and using a relative path (i.e. defining the alias while in the directory directly above what I want to assign) gives a Not found error. Anything else I can do?

I have to run these two commands:

export FREESURFER_HOME=/usr/local/freesurfer

source $FREESURFER_HOME/SetUpFreeSurfer.sh

Except the system is not my own, so I don't have permission to /usr/local/freesurfer . So I improvised and installed the program called freesurfer elsewhere (the full install path is /Raid6/users/bob/Downloads/freesurfer).

So I've been trying to set the alias FREESURFER_HOME to the freesurfer directory (I need to do this step because the SetUpFreeSurfer.sh file assumes its defined and uses it.

When I use the full path like so: export FREESURFER_HOME=/Raid6/users/bob/Downloads/freesurfer and then type $FREESURFER_HOME and press enter, I get a "Permission denied" error.

So I navigated to my Downloads directory such that typing ls would list, among other things, the freesurfer directory. And then I try export FREESURFER_HOME=freesurfer, but after I do that typing $FREESURFER_HOME and pressing enter gives me the message freesurfer: not found.

Not sure what to do/try from here, any help is greatly appreciated!

  • 1
    Note: FREESURFER_HOME is a shell variable here, not an alias. Commented Oct 17, 2019 at 20:56
  • @KamilMaciorowski Apologies for that and thank you for the correction! Looking into it, it seems that alises are different names for commands, while shell variables are different names for directories (or string in general?) Commented Oct 17, 2019 at 21:08
  • 1
    In your second-last paragraph, you tried to to execute “freesurfer” using the variable name. Did you check if the script/binary it points to is executable? I have seen a number of times when you download something from the Internet and simply store it, it may not have the executable permissions. Also, for your /Raid6 path you provide two directories assuming two different users. Are you able to log on as either of them?
    – Phoenix
    Commented Oct 18, 2019 at 4:44
  • And finally: in the last paragraph you try to run “freesurfer” without a path. If the location of this executable is not part of the PATH variable, you would need to provide the path to the executable (to the very least ./ assuming you are in the same directory when trying to run it).
    – Phoenix
    Commented Oct 18, 2019 at 4:49
  • @Phoenix Thank you very much for the help! The different paths was a typo actually (accidentally copied the wrong user's path as they're all in the same parent directory), fixed it now. I did try to execute freesurfer, but you're right: that's maybe not what I'm meant to do. All I have to do is successfully run source $FREESURFER_HOME/SetUpFreeSurfer.sh; that's my only goal. Thank you again for the help! Commented Oct 18, 2019 at 12:19

2 Answers 2


I leave everthing away, even the export directive.


In other languages, this would just be $FREESURFER_HOME = "freesurfer", a string assigment. In bash you decide at each use whether you mean string or value of variable



The dollar sign is the way to tell bash you mean the value/contents of that name.

After setting your variable, you can use it (with dollar sign)

source $FREESURFER_HOME/SetUpFreeSurfer.sh is what you want that variable for. You want to run/source a certain script in your modified fs-home directory. For one call it is exactly like source freesurfer/SetUpFreeSurfer.sh, if "freesurfer" is the contents.

If you type $FREESURFER_HOME as a command (first word is the command!), it gets expanded to its value "freesurf" (or whatever is the value), and that is not a existing command (-> not found).

In other situations, bad things have happened with valid commands in variables.

$  cmd='echo hello'
$  $cmd

Nothing happenes here, it is a friendly command -- but this kind of aliasing is questionable, at least. I think nobody does it, it would be disruptive. For a normal alias there is an extra built-in:

$  alias cmd='echo hello'
$  cmd

(Here no $ sign -- much better!)

(The export might be needed to propagate the variable. Does not change these facts at all. Put it back!)

  • The user seems to be using their variable correctly. Their issue seem to be more about where their files etc. are actually installed.
    – Kusalananda
    Commented Oct 18, 2019 at 15:27
  • @Kusalananda "typing $FREESURFER_HOME and pressing enter gives me the message freesurfer: not found" He is trying to use a variable as alias (see title also)
    – user373503
    Commented Oct 18, 2019 at 15:29
  • Yes, the confusion between aliases and using variables is also an issue. Understanding when to use $ on variable names, and when not to, is however not an issue.
    – Kusalananda
    Commented Oct 18, 2019 at 15:44
  • Thank you for the help! I believe I have boiled my confusion down to one question: do we have to use absolute paths when using the export command? For example, if my directory has a directory called NameyName, will running export name=/NameyName correctly make a variable that leads to the NameyName folder as desired? Or do I have to give the absolute path to NameyName all the way from the root for the export command to work? Commented Oct 18, 2019 at 17:27
  • @JamesRonald You have to assign it the way it will be used. The docs should say, often it is clear form context. Your $name has NameyName at the top level, with that slash, probably not "your" directory. With name=$HOME/NameyName you define it relative to your homedir, like /home/james/NameyName. With name=NameyName you assume it will be interpreted correctly. Sometimes exactly these things get mixed up, and a config file is not found. So don't make it worse!
    – user373503
    Commented Oct 18, 2019 at 18:09

I suppose an easier option would just to make a symlink pointing to the freesurfer directory with ln -s /usr/local/freesurfer freesurfer .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .