bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: weird problem -- path interpretted/eval'd as numeric expression


From: Linda Walsh
Subject: Re: weird problem -- path interpretted/eval'd as numeric expression
Date: Thu, 28 Mar 2013 19:44:51 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Lightning/0.9 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666


Greg Wooledge wrote:
> On Wed, Mar 27, 2013 at 02:37:16PM -0700, Linda Walsh wrote:
>> Greg Wooledge wrote:
>>>>>       Array variables may not (yet) be exported.
>>> Associative arrays can't be exported either.
> 
>>      Yeah, but they seem to get propagated anyway, I must save it somewhere 
>> like
>> I do _FPATH... i.e. each include adds teh included script into the INC array 
>> so
>> I don't
>> try to re-include it.
> 
> Well, I'm quite confident that they aren't propagated through the
> environment:
----
        Um... I deliberately have code in my bashrc and bash_env
to propagate some specific ARRAYS, as well as some specific ALIASES.

        I know bash doesn't natively support those functions.  I have
work-arounds that work for *most* purposes.

        It's a weird corner case that hasn't been important enough
to track down -- but it is a curiosity as to how/why/when a pathname
gets interpreted as an expression and ends up evaluating it as a divide by
0

This is weird:
Here's the function  (line numbers from offset of file)  The line#5 in the trace
below
is the same as line 84 below... how does it jump out of the function?!!?...It's
like the function "fails" and returns a div/0 -- that seems more likely...

It isn't the expression the "lib/Utils/needroot.shh", but I think the include
function
just exits after line 84, below with an error status that indicated division by 
0.

But the next line of the trace below that statement is from the original
"recycle_space" script -- it is the line BELOW the "include" function call
in the recycle script!

But it is LABELED (BASHES's prompt vars) as still being inside 'include'

I'm tending toward thinking this is a bash bug at this point -- cuz I can't
see anyway it include would exit at line 85 below (#5 in the trace),
throw out an error for line 7 of div/0 -- and remember, I did print out
with declare -p, _INC just before that -z test, in #87, and it did claim it
was an Associative Array.

And then the function continues executing code from the original source
file -- i.e. it lost it's place -- it's no longer in the function below, but
back in in the calling script -- but the line numbers from trace indicate
it still thinks it is in the function 'include'...

Most of these things do work in other cases... but something is weird here



 78 function include {
 79   [[ $1 ]] || return 1
 80   local fnc="$1"
 81   [[ $PATH != ${_SPATH:-} || ${#_FPATH[@]} -lt 1 ]] && {
 82     unset _FPATH
 83     local -xa _FPATH=( $(IFS=:;echo $PATH) )
 84     export _SPATH="$PATH"
 85   }
 86
 87   if [[ -z ${_INC["${fnc:-}"]:-}  ]]; then
 88     for pw in "${_FPATH[@]}"; do
 89       [[ ${pw:0-1:1} != / ]] && pw+='/'
 90       local fn="${pw}${fnc}"
 91       if [[ -r $fn  || -r $fn.shh && fn+=".shh"  ]]; then
 92         source "$fn"  || {
 93           stat=$?
 94           echo "Error: include of \"$fnc\" did not return 0 status"
 95           return $stat
 96         }
 97         _INC["$fnc"]="$fn"
 98         return 0
 99       fi
100     done
101     echo "Cannot find \"$fnc\" in \"$PATH\"" >&2
102     exit 2
103   fi
104 }

The trace shows numbers from the start of the function:
>>./recycle_space#14> include lib/Util/needroot.shh
>>#0(include)> [[ -n lib/Util/needroot.shh ]]
>>#1(include)> local fnc=lib/Util/needroot.shh
>>#2(include)> [[ 
>>/home/law/bin:/home/law/bin/lib:.:/sbin:/usr/local/sbin:/home/law/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/dell/srvadmin/bin:/usr/sbin:/home/law/bin/lib:/etc/local/func_lib:/home/law/lib
>> != '' ]]
>>#3(include)> unset _FPATH
>>#4(include)> _FPATH=($(IFS=:;echo $PATH))
>>>#4(include)> IFS=:
>>>#4(include)> echo /home/law/bin /home/law/bin/lib . /sbin /usr/local/sbin 
>>>/home/law/bin /usr/local/bin /usr/bin /bin /usr/bin/X11 /usr/X11R6/bin 
>>>/usr/games /opt/kde3/bin /usr/lib/mit/bin /usr/lib/mit/sbin 
>>>/opt/dell/srvadmin/bin /usr/sbin /home/law/bin/lib /etc/local/func_lib 
>>>/home/law/lib
>>#4(include)> local -xa _FPATH
>>#5(include)> export 
>>_SPATH=/home/law/bin:/home/law/bin/lib:.:/sbin:/usr/local/sbin:/home/law/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/dell/srvadmin/bin:/usr/sbin:/home/law/bin/lib:/etc/local/func_lib:/home/law/lib
>>#5(include)> 
>>_SPATH=/home/law/bin:/home/law/bin/lib:.:/sbin:/usr/local/sbin:/home/law/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/dell/srvadmin/bin:/usr/sbin:/home/law/bin/lib:/etc/local/func_lib:/home/law/lib

-------
./recycle_space: line 7: lib/Util/needroot.shh: division by 0 (error token is
"/needroot.shh")
>>#20(include)> Recycle_pat='\.recycle$'
>>>#25(include)> type -P ls





reply via email to

[Prev in Thread] Current Thread [Next in Thread]