LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-08-2012, 02:11 AM   #1
zaayu87
LQ Newbie
 
Registered: Sep 2012
Location: India
Posts: 6

Rep: Reputation: Disabled
Post 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.
 
Old 10-08-2012, 04:21 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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"
 
1 members found this post helpful.
Old 10-08-2012, 05:37 AM   #3
zaayu87
LQ Newbie
 
Registered: Sep 2012
Location: India
Posts: 6

Original Poster
Rep: Reputation: Disabled
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.
 
Old 10-08-2012, 10:40 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
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.

Last edited by David the H.; 10-08-2012 at 10:44 AM. Reason: minor wording edits
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using alias's and editing the bashrc cynicalpsycho Linux - Newbie 11 05-07-2009 12:41 AM
bashrc alias issue noir911 Linux - General 1 08-22-2006 05:24 AM
My first alias in .bashrc...'apostrophes 'getting' in the way?' Baix Linux - Newbie 3 06-17-2004 02:36 PM
alias and .bashrc whaase Linux - General 3 11-02-2003 07:03 PM
alias and bashrc Haldir Linux - Newbie 3 06-14-2002 05:11 PM


All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration