LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problems defining an alias in .bashrc (https://www.linuxquestions.org/questions/linux-newbie-8/problems-defining-an-alias-in-bashrc-4175431185/)

zaayu87 10-08-2012 02:11 AM

Problems defining an alias in .bashrc
 
Hi,

I tried creating an alias under .bashrc file of my home dir.. shown below - "list1"

# User specific aliases and functions

PATH=/sbin:/usr/sbin:$PATH
alias list1='ls -lrt /tmp/zaayu/ | tail -3'



But it doesn't work. when i list out the aliases on system, the alias i created doesn't show up.. neither i am able to run it on the prompt.

Please suggest.

pixellany 10-08-2012 04:21 AM

I think you may need to restart the system for things in .bashrc to take effect.

Note the "normal" way of changing the PATH:
Code:

export PATH="$PATH:/sbin:/usr/sbin"

zaayu87 10-08-2012 05:37 AM

Thanks for the correction in the PATH env var..

Is there no other way to get the changes permanent without the system restart? as I am not the root admin for the box.

David the H. 10-08-2012 10:40 AM

You don't need to restart the system. You just need to re-source the startup file.

Code:

. /path/to/bashrc        #the dot is the source command
Sourcing means reading the file into the current shell environment and executing everything in it, just as if it were manually run.

So of course you can also simply run the commands manually once so that they come into affect in the current session.

For login shells you may have to log out and back in again, but that's a far cry from having to restart. But then again, login shells don't read the .bashrc.


Now for the theory. Nothing you set in the shell is ever "permanent". When a shell starts, it automatically sources one or more start-up files, just as above. This allows you to run commands that configure the default environment or do other things. The shell may also inherit a few settings from the parent process (such as the system init), which is how you can get a default path even without any startup files.

And whenever a shell (or any process, really) exits, its environment is lost too.


All times are GMT -5. The time now is 09:56 PM.