1820310 Members
2388 Online
109623 Solutions
New Discussion юеВ

Re: alias

 
navin
Super Advisor

alias

Hello All,
I have to set up an alias for the command ,user has sh as login shell and few times he changes to bash and then execute the command which i'm trying to setup alias.
But it is not stable .Means it works if i do su - user. But for user it works until the session closes.Please let me know how can i make this as permanent for the user as well as system wide so that the alias will be there permanently
thanks much
Learning ...
4 REPLIES 4
Matti_Kurkela
Honored Contributor

Re: alias

Aliases are not inherited from the parent process to its children. If your user switches from sh to bash, the new bash shell will start as "interactive non-login shell", which means it doesn't read /etc/profile nor ~/.profile. Instead, it reads /etc/bash.bashrc and ~/.bashrc.

The exported environment variables are inherited from the parent shell, so they are not a problem - but the aliases will be gone.

Read the "INVOCATION" chapter in the man page of your bash shell to understand the process.

To get your alias to work, you must define it so that both login and non-login shells will read the definition. That may mean setting it in two places: /etc/profile (for login shells, both sh and bash) and /etc/bash.bashrc (for non-login bash).

If your /etc/bash.bashrc is fully POSIX sh compatible (=contains no bash-specific extensions), you might avoid duplication by defining the aliases in /etc/bash.bashrc only and making /etc/profile read that file by adding this to /etc/profile:
. /etc/bash.bashrc

MK
MK
Rasheed Tamton
Honored Contributor

Re: alias

Hi Navin,

For bash shell for the user, you have to put alias commands in .bashrc in the home dir of the user.

vi /home/user/.bashrc
alias ll='ls -l'

Rgds.
Dennis Handly
Acclaimed Contributor

Re: alias

>I have to set up an alias for the command

It might be easier to use a script in another PATH for that command.
You can also use functions that are found in FPATH.
Peter Nikitka
Honored Contributor

Re: alias

Hi,

I would create a seperate file containing aliases and source that from the different places needed, e.g. use
/etc/aliases.local
and then in /etc/profile, and so on:
...
# include aliases
[ -s /etc/aliases.local ] && . /etc/aliases.local
...

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"