LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2005, 05:39 PM   #1
rharris72
Member
 
Registered: Nov 2005
Posts: 32

Rep: Reputation: 15
variable one script to another


can a variable from one file be used in another so for instance

if say test.sh had

var="hello"

could i call that var form say test.1.sh

so it would display the var when i run test1.sh

basically i am writing a http interface with user input outputing that to a file and would like to use another file to exec all the variables

thanks in advance
 
Old 11-22-2005, 06:55 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
Only if you source the script(s), and the variables are
exported ...


Cheers,
Tink
 
Old 11-23-2005, 01:17 AM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Tinkster is correct. Another alternative is to use the "." to read an initialization file.

EXAMPLE:
vi myenv =>
Code:
export ONE=1
export TWO=2
export THREE=tres
vi myscript =>
Code:
echo "BEFORE: ONE= $ONE, TWO= $TWO, THREE= $THREE."
. ./myenv
echo "AFTER: ONE= $ONE, TWO= $TWO, THREE= $THREE."
./myscript =>
Quote:
BEFORE: ONE= , TWO= , THREE= .
AFTER: ONE= 1, TWO= 2, THREE= tres.
'Hope that helps .. PSM

Last edited by paulsm4; 11-23-2005 at 01:18 AM.
 
  


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
Shell Script Random Variable Daniel Programming 14 12-03-2007 05:00 AM
Query about script variable phantomdude Linux - Newbie 1 03-18-2004 11:21 AM
bash script $n variable expansion cortez Programming 6 12-08-2003 04:03 PM
Bash script renaming a variable zael Programming 3 09-30-2003 04:37 AM
Specifying a variable without editing my script everytime MasterC Programming 6 04-23-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration