Re: passing environment variables back to shell
Matt Price <matt.price@utoronto.ca> writes:
> anyone know if it's possible to pass the value of variables assigned
> within a bash script back out to the executing shell?
No, unless you run the child script using the '.' builtin.
> 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.
You don't want an environment variable at all, then. Persistent state
generally gets stored in files; someone else also suggested using
trying to get the last-known IP address from iptables or ifconfig.
> /usr/local/scripts/gethomeip :
> -------------------------------------------
> #!/bin/bash
> HOSTRESULT=`host youknowwho.dyndns.org`
> RESULTIP=`echo ${HOSTRESULT##[^0-9]*[^0-9\.]}`
MATTSIP=`cat /etc/mattsip`
...
> #set the new value
> MATTSIP=$RESULTIP
> echo "$MATTSIP"
echo "$MATTSIP" > /etc/mattsip
--
David Maze dmaze@debian.org http://people.debian.org/~dmaze/
"Theoretical politics is interesting. Politicking should be illegal."
-- Abra Mitchell
Reply to: