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?

Adam
  • 2,638

1 Answers1

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 *.

muru
  • 197,895
  • 55
  • 485
  • 740