I have created an alias for a path that I use often like that:

alias example='/home/user/directory/'

(in the home/.bash_aliases)

The problem is that I want to access that directory via terminal like:


but it doesn't work.

This is the first time that I try to create an alias and I think that I am missing something. What am I doing wrong?


An alias is a shorthand for a command or something that ultimately evaluates to a command. It cannot be used like a variable, which can be used as anything, but has specific syntax. For example, the following creates a variable and uses it:

ls "$example"/file

A variable is evaluated using $. Always remember to enclose your variables in quotes ("") - this helps prevent against unexpected results when your variable contains spaces or special characters, like *.

| improve this answer | |
  • Thank you, if I want to use it as a variable in which file should I add the definition? – Adam Apr 24 '15 at 1:25
  • @Adam .bashrc should do fine. – muru Apr 24 '15 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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