LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Variables between shell scripts (https://www.linuxquestions.org/questions/linux-newbie-8/variables-between-shell-scripts-809082/)

Potatos 05-20-2010 09:26 AM

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 :D

colucix 05-20-2010 09:32 AM

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.


All times are GMT -5. The time now is 04:56 PM.