Thus spake Andrea Righi ([EMAIL PROTECTED]):
Brian Elliott Finley wrote:
Thus spake Andrea Righi ([EMAIL PROTECTED]):
Brian Elliott Finley wrote:
Better yet, is there any reason not to source the functions prior to
sourcing the variables?
Some functions in particular for the monitoring stuff are
variables.txt dependent...
This is true, but sourceing the functions does not _execute_ the
functions. It simply puts them into shell memory so that they are
available for execution.
Yes, but some functions (like send_monitor_msg) use some varibles
($DEVICE for example). When the function is loaded in memory if $DEVICE
is not set it will remain null...
I don't find that to be the case. Perhaps you're having some
other strangeness that affects this in some way?
Please do this test as an example. The test_functions file includes a
function with lines cut and pasted from the send_monitor_msg function in
our functions file:
1) copy the two attached files into /tmp
2) chmod +x test_script
3) ./test_script
It should return the mac address for your eth0. And you'll note that
in "test_script", $DEVICE is not set until _after_ the functions are
sourced.
You can even change the script to use ash instead of sh, and you'll get
the same behavior.
Cheers, -Brian
also if you source the variables.txt
later...
-Andrea
It's fine that the functions be sourced first, even prior to the
variables being put into the environment, as long as the variables are
there prior to the functions being called, or executed.
Cheers, -Brian
--
Brian Elliott Finley
Mobile: 630.631.6621
send_monitor_msg() {
# Get the client mac address.
if [ -z "$mac" ]; then
mac=`ifconfig $DEVICE 2>/dev/null | sed -ne "s/.*HWaddr //p" | sed "s/
//g" | sed s/:/./g`
fi
echo $mac
}
#!/bin/sh
. ./test_functions
DEVICE=eth0
send_monitor_msg