why alias names defined in .bashrc file are not working?

12

4

I have give alias names in .bashrc file like below. But the alias names are not working. why?

alias c='clear'
alias l='ls -lt'
alias h='history'
alias d='ls -lt |grep "^d"'

export ORACLE_HOME=/ora11gr2/app/oracle/product/11.2.0/db2
export ORACLE_LIB=/ora11gr2/app/oracle/product/11.2.0/db2/lib
export PATH=$ORACLE_HOME/bin:/usr/vac/bin:/usr/vacpp/bin:.    
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:.

Venkatesh

Posted 2012-06-27T04:21:20.093

Reputation: 121

2Are you saying you get the environement variables but not the aliases, or you get none of it? – Paul – 2012-06-27T04:54:07.843

1May be a separate issue, but you wipe out your PATH. You should reference your old PATH in any setting, e.g. export PATH=$PATH:$ORACLE_HOME/bin:/usr/vac/bin:/usr/vacpp/bin:. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib – Rich Homolka – 2012-06-27T15:38:09.813

Answers

28

Did you source your .bashrc file after you changed it? Try:

. ~/.bashrc

Then your shell should see the changes. Alternatively, you can terminate and restart your shell.

p.s.

When you run from a script, load this first ref

shopt -s expand_aliases

Fran

Posted 2012-06-27T04:21:20.093

Reputation: 4 774

2This solved my problem! Before that, I even tried to log out and in again through the SSH, but nothing happened. The alias was still not available. Looks like I have to do this every time I do the SSH! Do you know why is this happening? – Vladimir Despotovic – 2017-10-19T17:05:00.110

I don't recommend re-running .bashrc. It can cause some duplicate and swollen values. Why not exit and start a new shell? It will load the updated .bashrc file. – AlikElzin-kilaka – 2018-07-10T06:34:21.457

2

This may happen because your PATH has not been set correctly to use all alias referenced binaries absoulte path. I.e ls exists under /bin/ls.

Can you give a try using "export PATH=$PATH:$ORACLE_HOME/bin:/usr/vac/bin:/usr/vacpp/bin:." or somthing like "export PATH=$ORACLE_HOME/bin:/usr/vac/bin:/usr/vacpp/bin:/bin:/sbin/:/usr/sbin

if not, then use "which" to find the path directory for individual alias ref binaries (which history).

Sivakumar Manickam

Posted 2012-06-27T04:21:20.093

Reputation: 21

1

Questions to ask yourself are:

  • Is the ~/.bashrc already executed in your shell. It only runs when the shell is started. If you open a new shell (execute bash) it should be. With alias you should see all your aliases printed.
  • Second thing to ask: are the programs in your aliases available. At least h (alias history) should definitely work, because it is builtin.

Fra Orolo

Posted 2012-06-27T04:21:20.093

Reputation: 11

1

Maybe you are trying to define your aliases in your .bashrc that are already global.

Usually your aliases in .bashrc are defined before the /etc/bashrc call. Try to define them after.

Here an example of your .bashrc:

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
alias c='clear'
alias l='ls -lt'
alias h='history'
alias d='ls -lt |grep "^d"'

export ORACLE_HOME=/ora11gr2/app/oracle/product/11.2.0/db2
export ORACLE_LIB=/ora11gr2/app/oracle/product/11.2.0/db2/lib
export PATH=$ORACLE_HOME/bin:/usr/vac/bin:/usr/vacpp/bin:.    
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:.

Mario Taddei

Posted 2012-06-27T04:21:20.093

Reputation: 11

Terrific answer! I'm seeing this consistently in AWS Linux AMI's – rainabba – 2016-02-27T11:26:04.990

0

Just in case any MacOS users come looking for this answer, I tried this on my MacBook and even restarting the Terminal would not load the new alias definitions. The only way I could get it to work was to source ~/.bashrc every time. I then tried moving my alias definitions to ~/.bash_profile and this is what did the trick.

Mig82

Posted 2012-06-27T04:21:20.093

Reputation: 133