Re: Passing variables from shell script to another



On Mon, 31 Mar 2008 03:12:16 -0700 (PDT), Nezhate wrote:
Hi all,
I've just started to learn shell programming. I have 2 scripts and
wont to pass some variables from script1 to script2
exp:
Script1 is:
#!/bin/sh
echo "Enter 3 data"
read tmp1 tmp2 tmp3

. ./script2.sh $tmp1 $tmp2 $tmp3
exit 0

script2 is:
#!/bin/sh
tst_fct (){
^^^^^^^^^^^
var1=$1
var2=$2
var3=$3
echo "var1=$var1, var2=$var2, var3=$var3"

}
^
exit 0

as result I got:
$ ./script1.sh
Enter 3 data
foo bar nothing
var1=, var2=, var3=

why this doesn't work ?

It works exactly as you've programmed it but not as intended.
In script2 it created a function called tst_fct but you never
called it. You have two choices, either remove the highlighted
sections above or call the function inside script2 with the
variables.

--
Linux Home Automation Neil Cherry ncherry@xxxxxxxxxxx
http://www.linuxha.com/ Main site
http://linuxha.blogspot.com/ My HA Blog
Author of: Linux Smart Homes For Dummies
.