Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 10-02-2003, 03:09 PM   #1
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:

export MY_VAR

This doesn't seem to work? What am I doing wrong?
Old 10-02-2003, 04:24 PM   #2
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.

Old 10-02-2003, 04:25 PM   #3
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)


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
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


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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:16 AM.

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