LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-02-2003, 03:09 PM   #1
kharris
LQ Newbie
 
Registered: Aug 2003
Posts: 15

Rep: Reputation: 0
Setting an environment variable


I am trying to set an environment variable using a script as follows:

#!/bin/sh
MY_VAR=/etc
export MY_VAR

This doesn't seem to work? What am I doing wrong?
 
Old 10-02-2003, 04:24 PM   #2
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
Let me take a stab in the dark here. Are you using this variable within the script itself? I believe the '#!/bin/sh' line makes the shell script execute within a subshell. Therefore the variable would only be set within that subshell only.

Maybe?
 
Old 10-02-2003, 04:25 PM   #3
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
My my limited knowledge or the way I look at it when the script is executed it is being run "by" the shell not "in" the shell as such so the shell doesn't have any knowledge of the variable your are exporting although any other things/scripts you call within the script should be aware of the exported variable as they are in turn being run by the script and can access the environment that is available to the inital script

To make the commands in the script be run as if they are executed at the current shells command line

. ./myscript (that's a dot space dot)

or

source ./myscript

It's not a very technical explanation or perhaps even too accurate a description (although certainly slightly confused ) but it's the way my wee head likes to look at it.


Someone else might explain it better or correct me
 
Old 10-02-2003, 04:38 PM   #4
magnum818
LQ Newbie
 
Registered: Sep 2003
Location: Northridge-California-USA
Distribution: Redhat
Posts: 10

Rep: Reputation: 0
Are you trying yo set the variable a boot time? If so you need to add the commands to your ~/.bashrc file
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
environment variable setting chii-chan Linux - General 5 01-23-2009 07:29 PM
setting environment variable kb_ganesh Ubuntu 3 09-10-2005 01:58 PM
Setting up a environment variable Hiper1 Linux - Newbie 3 03-08-2005 08:43 AM
setting environment variable DISPLAY jpan Debian 4 10-15-2004 06:09 PM
Trouble setting environment variable exitsfunnel Linux - Software 4 10-06-2004 06:49 AM


All times are GMT -5. The time now is 02:45 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration