[ale] How to pass vars to lots of shell scripts?

Scott Plante splante at insightsys.com
Fri Oct 18 14:23:58 EDT 2013


If I understand what you're asking, this is what the export keyword is for. 


----------x.sh------------- 
X=test 
y.sh 
export X 
y.sh 
-----------y.sh---------- 
echo X=$X 
------------------------ 
$ ./x.sh 
X= 
X=test 

----- Original Message -----

From: "leam hall" <leamhall at gmail.com> 
To: "Atlanta Linux Enthusiasts" <ale at ale.org> 
Sent: Friday, October 18, 2013 1:03:58 PM 
Subject: Re: [ale] How to pass vars to lots of shell scripts? 







So far, that's what I'm thinking. The process would be: 

master script zeros out the param file 
master script takes options given to it and writes to a param file 
For example: 

params.sh 
TEST=0 # Test for condition, default true 
FAIL=1 # Has not failed yet 
FIX=1 # Default to do not fix 

Called script looks something like: 

. params.sh 

THIS_VAR=0 

<run something that sets THIS_VAR to not 0 if the test fails> 


if [ THIS_VAR -ne 0 ] 
then 
FAIL=0 

fi 

if [ $TEST -eq 0 ] 
then 

if [ $FAIL -ne 0 ] 

then 

echo "This test passed" 

else 

echo "This test failed." 

fi 

fi 


# TEST and FIX are separate; some runs might just test, some will fix. 


if [ $FAIL -eq 0 ] && [ $FIX -eq 0 ] 
then 
echo "Time to fix this bad boy..." 
<do fix stuff> 
fi 





On Fri, Oct 18, 2013 at 12:42 PM, chip < chip.gwyn at gmail.com > wrote: 



Could this be done by setting an environment variable then test for the value in your script and branch to do whatever. 


--chip 





On Fri, Oct 18, 2013 at 12:01 PM, leam hall < leamhall at gmail.com > wrote: 

<blockquote>













Hey all, 

I have a master script that calls a couple hundred other scripts. Each of the "other" scripts can also be called in their own. 

What I'm thinking about is having a variable like "test" or "fix" be set, so that if the "other" scripts run they will get a parameter without me having to put a getopts stanza in each script. 

So maybe: 

. ./my_vars 

if [ $TEST ] 

then 
... 


or 

if [ -f ./TEST ] 
then 
... 

Thoughts on the best way to do this? I'm not saying my ideas are the only way, just what comes to mind. 

Leam 













-- 

Mind on a Mission 
_______________________________________________ 
Ale mailing list 
Ale at ale.org 
http://mail.ale.org/mailman/listinfo/ale 
See JOBS, ANNOUNCE and SCHOOLS lists at 
http://mail.ale.org/mailman/listinfo 







-- 
Just my $.02, your mileage may vary, batteries not included, etc.... 
_______________________________________________ 
Ale mailing list 
Ale at ale.org 
http://mail.ale.org/mailman/listinfo/ale 
See JOBS, ANNOUNCE and SCHOOLS lists at 
http://mail.ale.org/mailman/listinfo 


</blockquote>



-- 

Mind on a Mission 
_______________________________________________ 
Ale mailing list 
Ale at ale.org 
http://mail.ale.org/mailman/listinfo/ale 
See JOBS, ANNOUNCE and SCHOOLS lists at 
http://mail.ale.org/mailman/listinfo 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20131018/c356eeae/attachment.html>


More information about the Ale mailing list