LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 04-16-2011, 07:30 PM   #1
BMan8577
Member
 
Registered: Apr 2011
Posts: 73

Rep: Reputation: 0
Question How do you use environment variables in the .bashrc file...


I am trying to include my directory /usr/sbin in it's serch path for executable files using an environment variable. Would the input be: PATH="/usr/sbin"? And also upon start up, my shell should create the PRINTER environment variable which should resolve to the word sales...would that input be: PRINTER="sales"? If someone could help me with these two questions, this would be very helpful thanks.
 
Old 04-16-2011, 07:46 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Add the commands in $HOME/.profile or $HOME/.bash_login, whichever you are currently using.

e.g.
PATH="$PATH":/usr/sbin/
PRINTER="sales"
export PATH PRINTER

On some systems, the .profile command will source the .bashrc file, but having PATH= in .bashrc will add /usr/bin/ everytime you start a new interative terminal or subshell. Using .profile is the best place for setting variables and aliases.
 
Old 04-17-2011, 12:35 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by BMan8577 View Post
Would the input be: PATH="/usr/sbin"?
That will delete everything from your PATH and replace it with /usr/sbin. Use this instead:

Code:
PATH=$PATH:/usr/sbin
Items in PATH are separated with colons (":").
 
Old 04-17-2011, 02:16 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by jschiwal View Post
Add the commands in $HOME/.profile or $HOME/.bash_login, whichever you are currently using.

e.g.
PATH="$PATH":/usr/sbin/
PRINTER="sales"
export PATH PRINTER
You can also use the syntax:
Code:
export PATH="$PATH":/usr/sbin
export PRINTER="sales"
As far as I know, there is no effective difference; it is just personal preference. If a variable is already exported, it doesn't hurt to 're-export' it. The 'export' keyword causes the variable to be inherited by child processes that get spawned by the current shell process. Otherwise, the variables only exist within the context of the current shell process (and sometimes that is what you want).

--- rod.
 
  


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
to export environment variables in a file vinayakshinde1987 Linux - Newbie 9 10-28-2010 05:10 AM
exporting environment variables from a file? concoran Linux - Newbie 4 04-19-2008 06:49 PM
Setting up environment variables for j2se and j2ee on linux in .bashrc vitalstrike82 SUSE / openSUSE 1 03-30-2008 08:26 AM
how to add environment variable to .bashrc file hasan Linux - General 7 10-03-2003 05:43 PM
how to add environment variable to .bashrc file? hasan Red Hat 1 10-03-2003 02:37 PM


All times are GMT -5. The time now is 10:51 PM.

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