LinuxQuestions.org
Review your favorite Linux distribution.
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 07-13-2008, 09:18 PM   #1
dina3e
Member
 
Registered: Mar 2008
Location: Bangalore
Distribution: Enterprise Red Hat linux
Posts: 98

Rep: Reputation: 16
Smile using a variable in another variable.


my problem is, i have to use some of the variable from one shell script to other shell script.Where the varible is already defined in first script and we just simple use the defined variable in the second script. (like c static and extern variable storage classes)
 
Old 07-13-2008, 11:03 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
To pass a variable to another script depends on how you invoke or use the other script:

*) if you source (.) a file, all variables are available, as this just reads to contents into the current shell process
*) if you call the second script by way of execution, you must pass variables either via exported environment variables or by command line arguments.
 
Old 07-17-2008, 10:51 PM   #3
dina3e
Member
 
Registered: Mar 2008
Location: Bangalore
Distribution: Enterprise Red Hat linux
Posts: 98

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Mr. C. View Post
To pass a variable to another script depends on how you invoke or use the other script:

*) if you source (.) a file, all variables are available, as this just reads to contents into the current shell process
*) if you call the second script by way of execution, you must pass variables either via exported environment variables or by command line arguments.
i have define some of the variable in one file and later i use these variables. and these variable act as static data type.so how i do link all these and access these data type.
 
Old 07-17-2008, 11:17 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Code:
$ cat file1

var1=10

$ cat file2
echo Before: $var1
. ./file1
echo After: $var1

$ sh ./file2
Before:
After: 10
 
  


Reply

Tags
variables


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 scripting : how to name a variable with the value of another variable JimOrJoe Programming 9 06-15-2008 09:36 PM
Help: removing a variable substring from a string variable in sh script gnparsons Programming 2 06-04-2008 05:21 PM
Replace variable with user defined variable ce124 Programming 10 04-13-2007 09:29 AM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 11:23 AM
Scripting: accessing a variable stored in a variable? tomolesonjr Linux - Newbie 5 05-05-2006 08:47 PM


All times are GMT -5. The time now is 11:58 PM.

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