Erick Jones
Erick Jones

Reputation: 109

How can I set an alias for a command in bash that works in any folder?

So, I have created a bash_profile and set the aliases, but they just work in my home folder (cd/). Is there a way where I can use this aliases whenever I am in? I am using the Bash in MAC OS X.

Thanks brothers.

EDIT:

It appears these aliases are for cd commands to folders in the home folder or for scripts in the home folder. For example:

alias jobs2015='cd Documents/erickjones/_Aotopo/_jobs/2015

Upvotes: 1

Views: 1028

Answers (1)

rghome
rghome

Reputation: 8819

I presume your aliases are either for cd commands to folders in your home folder or to run scripts that are in your home folder.

Your options are:

  1. Prefix the command or cd-directories by $HOME/ when you define the aliases.
  2. For commands, include the HOME folder (or other folder where your scripts are) in the PATH.
  3. For cd, include the HOME folder in the CDPATH variable.

PATH is the list of folders that are searched to find a command that you are executed. YOu can add directories to it, but be careful not to delete existing ones. See here: PATH

CDPATH is a list of folders where cd will look for the folder to search. See here CDPATH

Upvotes: 1

Related Questions