weird bash script error

Paul Fox pgf at brightstareng.com
Mon Jul 16 12:29:06 UTC 2007


 > Hi,
 > 
 > I've the following script, that reads a set of parameters from a .conf 
 > file and load it into vars... it works OK on my Debian Box but... It 
 > just produces no answer on BusyBox with the exception of a blank line 
 > for each "echo" in the script...

your script starts with "#!/bin/bash".  do you really have bash running
under busybox?  or did you make the mistake of linking "ash" to "bash"?
they're not the same thing.

where is awk coming from?  is it the busybox awk?  if so, i wouldn't
be surprised at all if it doesn't function exactly like "real" awk
(for almost any value of "real") for some of what you're doing.  you
might want to start your debugging there.

paul

 > 
 > So I'm thinking about it doesn't put values on the vars (that's why it 
 > produces blank echo lines...)
 > 
 > Anybody knows what can be going wrong? Something could be different on 
 > BB? I looks alright to me!
 > 
 > Thanks a lot!!
 > ------
 > #!/bin/bash
 > # Function: get_config_list config_file
 >           # Purpose : Print the list of configs from config file
 > get_config_list()
 > {
 >    typeset config_file=$1
 > 
 >    awk -F '[][]' '
 >       NF==3 && $0 ~ /^\[.*\]/ { print $2 }
 >    ' ${config_file}
 > }
 > 
 > # Function : set_config_vars config_file config [var_prefix]
 > # Purpose  : Set variables (optionaly prefixed by var_prefix) from 
 > config in config file
 > set_config_vars()
 > {
 >    typeset config_file=$1
 >    typeset config=$2
 >    typeset var_prefix=$3
 >    typeset config_vars
 > 
 >    config_vars=$(
 >         awk -F= -v Config="${config}" -v Prefix="${var_prefix}" '
 >         BEGIN {
 >            Config = toupper(Config);
 >            patternConfig = "\\[" Config "]";
 >         }
 >         toupper($0) ~ patternConfig,(/\[/ && toupper($0) !~ patternConfig) {
 >            if (/\[/ || NF <2) next;
 >            sub(/^[[:space:]]*/, "");
 >            sub(/[[:space:]]*=[[:space:]]/, "=");
 >            print Prefix $0;
 >         } ' ${config_file} )
 > 
 >    eval "${config_vars}"
 > }
 > 
 > #
 > # Set variables for all config from config file
 > #
 > file=BlackBox.conf
 > for cfg in $(get_config_list ${file})
 > do
 >    echo "--- Configuration [${cfg}] ---"
 >    unset $(set | awk -F= '/^cfg_/  { print $1 }') cfg_
 >    set_config_vars ${file} ${cfg} cfg_
 >    set | grep ^cfg_
 > done
 > echo $cfg_WIFI #Testing boolean wifi value
 > echo $cfg_NTP_Server # Testing value for NTP Server IP
 > 
 > 
 > _______________________________________________
 > busybox mailing list
 > busybox at busybox.net
 > http://busybox.net/cgi-bin/mailman/listinfo/busybox

=---------------------
 paul fox, pgf at brightstareng.com



More information about the busybox mailing list