1

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:

example/file

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?

1 Answer 1

3

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:

example='/home/user/directory/'
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 *.

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

You must log in to answer this question.

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