Results 1 to 4 of 4
I'm trying to use an environment variable in a script, but it keeps returning a null value. The thing that is confusing me is that when I use it OUTSIDE ...
- 01-27-2009 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 7
Use environment variables in script?
I'm trying to use an environment variable in a script, but it keeps returning a null value. The thing that is confusing me is that when I use it OUTSIDE the script, on the command line, it works fine. Why does the $USER variable work ok, but not the $ARCHIVE variable I created? I created it by typing: ARCHIVE="/home/brad/archives/"
The Script:
The Command Line:Code:#!/bin/bash echo $USER echo $ARCHIVE
Thanks!Code:$ echo $ARCHIVE /home/brad/archives/ $ ./TEST brad $
- 01-27-2009 #2Just Joined!
- Join Date
- Jan 2009
- Posts
- 7
Ha! I just answered my own question. Wouldn't you know it, as soon as I post the question I figure it out. For anyone else who was wondering, I just changed
toCode:$ ARCHIVE="/home/brad/archives/"
Apparently this expands the scope so I can use it in my script.Code:$ export ARCHIVE="/home/brad/archives/"
- 01-27-2009 #3
More specifically, when you export a variable, it is accessible to other programs that are launched from the shell. When you don't export it, it is only available to the shell itself.
DISTRO=Arch
Registered Linux User #388732
- 01-27-2009 #4Just Joined!
- Join Date
- Jan 2009
- Posts
- 7
Thanks for the info!


Reply With Quote