LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-20-2010, 09:26 AM   #1
Potatos
LQ Newbie
 
Registered: Apr 2010
Distribution: Fedora 13
Posts: 20

Rep: Reputation: 1
Question Variables between shell scripts


Hi

Ive created some custom shell scripts to run during the kernels boot process (they are called from the init script).

I was wondering if there's any way to assign a variable that can be accessed between different scripts.

For example my first script checks which type of pc i am installing on and assigns the hard drive location to a variable.

HARDDRIVE = "/dev/sda1"

at the end of the script it calls another script. In this script I cant reference HARDDRIVE as it is blank, to get around this I need to repeat the same code for assigning it.

Its more of a space/aesthetics issue but I figured someone might know the solution off the top of their head.

Thanks
 
Old 05-20-2010, 09:32 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If a script (child) is called by another script (parent) you can export variables in the parent script to make them available to the childs, e.g.
Code:
export HARDDRIVE="/dev/sda1"
If they are all childs of the parent shell, you can source them instead of executing, e.g.
Code:
. /path/to/script1
. /path/to/script2
. /path/to/script3
always using the export built-in inside the scripts.
 
  


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
about shell scripts global variables nesta Programming 2 01-05-2007 12:32 AM
Passing variables between shell scripts big_ginge21 Programming 3 09-26-2006 12:10 PM
Return variables in scripts Elec490 Programming 8 08-22-2005 09:10 AM
Exporting variables through scripts rammya Programming 1 04-14-2004 10:24 AM
Environment Variables in Scripts louisb Linux - General 3 01-15-2004 04:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:11 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