LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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-05-2004, 10:38 AM   #1
colly
Member
 
Registered: Feb 2004
Posts: 41

Rep: Reputation: 15
Basic shell script, please help


Hi,
I have wrote the following shell script to set a variable, ran the script but the variable wont set?
Here it is:

#! /bin/bash
export VARIABLE=test

Any ideas on how to get it to work?
Thanks,
Colm
 
Old 10-05-2004, 10:39 AM   #2
secesh
Senior Member
 
Registered: Sep 2004
Location: Savannah, GA
Distribution: Ubuntu, Gentoo, Mythbuntu, ClarkConnect
Posts: 1,154

Rep: Reputation: 47
you must reference VARIABLE using $VARIABLE

your code works

Code:
#!/bin/bash
export VARIABLE=test
echo $VARIABLE
 
Old 10-05-2004, 10:45 AM   #3
colly
Member
 
Registered: Feb 2004
Posts: 41

Original Poster
Rep: Reputation: 15
No ive tried that and when I run the script it echos out VARIABLE and that works.
But when I close the script and echo VARIABLE VARIABLE is unset I get nothing
 
Old 10-05-2004, 11:22 AM   #4
colly
Member
 
Registered: Feb 2004
Posts: 41

Original Poster
Rep: Reputation: 15
No problem I worked out that i needed to run the script using
. ./.name instead of
./.name when setting a enviromental variable using the script, I have no idea why but it worked.
 
Old 10-05-2004, 11:24 AM   #5
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Variables aren't exported from shell scripts back up to the parent's shell. If you want a shell script to set environment variables, you must source it (source <scriptname> or . <scriptname>) rather than running it normally.
 
  


Reply



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
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Help with basic bourne shell script rnj Programming 6 09-13-2005 08:41 PM
Basic Shell Script Help Vasquez Linux - Newbie 3 02-28-2005 07:14 PM
basic shell script help lin00b Linux - Newbie 2 10-08-2004 11:32 PM
basic shell script help coyote399 Linux - Newbie 6 04-14-2004 09:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:44 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
Open Source Consulting | Domain Registration