Re: passing environment variables back to shell
On Mon, June 23 at 11:05 PM EDT
Matt Price <matt.price@utoronto.ca> wrote:
> Hi,
>
> anyone know if it's possible to pass the value of variables assigned
> within a bash script back out to the executing shell? Or better yet,
> to all subsequent shells?
>
> I've written a tiny script to figure out the IP address of my
> (dynamically assigned) home computer and pass it to ipmasq on my work
> computer. I would like to run this as a cron job (probably daily,
> since my IP is pretty stable) and only rerun ipmasq if the new IP
> address differs from the old one. But I don't understand howto pass
> the new value back out to the executing environment.
>
> I think if you look at the script you'll see what I'm trying to do...
>
> /usr/local/scripts/gethomeip :
> -------------------------------------------
> #!/bin/bash
> HOSTRESULT=`host youknowwho.dyndns.org`
> RESULTIP=`echo ${HOSTRESULT##[^0-9]*[^0-9\.]}`
>
> # check the initial values
> echo "$RESULTIP"
> echo "$MATTSIP"
> if [ "$RESULTIP" = "$MATTSIP" ]
> then
> echo "no problem, the address is up to date"
> else
>
> #set the new value
> MATTSIP=$RESULTIP
> echo "$MATTSIP"
>
> # export -- but of course it only exports to daughter processes, not
> parent processes export MATTSIP
> ipmasq
> fi
>
> # check to make sure the variables been set within the script
> echo "$MATTSIP"
>
> -----------------------------------------------
>
> obviously export isn't what I'm looking for. Any ideas what I ought
> to substitute there? thanks,
slamson@callerio:/tmp$ cat return3
#!/bin/bash
echo ONE
echo TWO
echo THREE
slamson@callerio:/tmp$ set $(sh ./return3 ); echo :$1: :$2: :$3:
:ONE: :TWO: :THREE:
This passes them out. They won't have the names you specified,
though. Why not just run ipmasq from within the script, though?
HTH
>
> matt
>
>
Shawn Lamson
shawn.lamson@verizon.net
Debian GNU/Linux 3.0
Reply to: