passing environment variables back to shell
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,
matt
Reply to: