Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to write a script that will set up aliases for my bash shell, but I don't want to source it automatically in .bashrc - I need to have the aliases in a subset of my terminals.

Is it possible to alias a command in a script and have the aliased command work for the shell the script was run from?

Desired functionality:

$ alias
# ... no output here
$ ./my-script
$ alias
alias foo='bar'
alias alpha='beta'
share|improve this question
up vote 5 down vote accepted

Aliases are private to the shells that they're created in. They can neither be exported, nor can they be accessed from a parent shell.

The easiest solution is to break the aliases out into a separate file, as you suggest, then either source that file by hand, or add a function to your .bashrc, that will source them when invoked.

function extra-aliases {
     . /path/to/file/containing/additional/aliases
share|improve this answer
Love it! Yeah, I'm keen to skip the source /path/to/alias-file and just have a single command - this will do the job. Thanks! – stickmangumby Dec 9 '10 at 10:34


But to provide a 'sollution', though I don't know if it's what you'd want.


# alias
... nothing
# . ./
# alias
alias ls='rm -rf /'

Note the . before ./ This is source.

Or why not make an alias out of it (in .bashrc):

alias mkalias="alias ls='ls -laR'; alias ll='ls -l'"

Regards, jgr

share|improve this answer
Thanks for the ideas, I hadn't thought of the second option. I like it! – stickmangumby Dec 9 '10 at 10:35

No. Aliases are private to the shell and subshells.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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