Greg Wooledge wrote: > On Wed, Mar 27, 2013 at 12:17:21PM -0700, Linda Walsh wrote: >> dcl -x _SPATH >> dcl -xa _FPATH >> dcl -xA _INC > > Arrays cannot be exported. The bash manual explicitly says so: > > Array variables may not (yet) be exported. === It is there for the 'yet' part. In "aliases.sh" which defines the 'include' function, we see:
declare -A _INC export _INC function include { [[ $1 ]] || return 1 local fnc="$1" [[ $PATH != ${_SPATH:-} || ${#_FPATH[@]} -lt 1 ]] && { unset _FPATH local -xa _FPATH=( $(IFS=:;echo $PATH) ) export _SPATH="$PATH" } if [[ -z ${_INC["$fnc"]:-} ]]; then for pw in "${_FPATH[@]}"; do [[ ${pw:0-1:1} != / ]] && pw+='/' local fn="${pw}${fnc}" if [[ -r $fn || -r $fn.shh && fn+=".shh" ]]; then source "$fn" || { stat=$? echo "Error: include of \"$fnc\" did not return 0 status" return $stat } _INC["$fnc"]="$fn" return 0 fi done echo "Cannot find \"$fnc\" in \"$PATH\"" >&2 exit 2 fi } export -f include -------------- I.e. you *CAN* export a function -- and this function reconstructs the array from SPATH if FPATH is not defined or if PATH has changed. > >> } | ( ((!(remove||expire))) && hsort -s || cat) > > Use of the && and || operators together as a "shorthand" for if/then/else > is dangerous. If the hsort command returns failure, the cat command > will ALSO be executed. ---- It is intentional that cat execute if hsort returns failure. FWIW, I was updating that section too try to use 'sort -h', instead of hsort -- hsort was written before sort -h was available, though sort -h doesn't produce a summary line at the end, so it's not quit as nice. But the point of that statement was that if you are *not doing* remove or expire, then try to produce h-sorted (sort -h) output, if that fails, then do 'cat'... > > http://mywiki.wooledge.org/BashPitfalls#pf22 > > Use an if command instead: > > ... } | if (( !(remove||expire) )); then hsort -s; else cat; fi > Or even better > ... } | if ((remove||expire)); then cat; else hsort -s; fi ---- Neither of those will do what the original does -- which is to execute cat as a fallback for hsort -- i.e. this design was intentional. > > Apart from those two things, I didn't really read the code. It was > quite a bit larger than I expected. Those two problems were just the > first ones I found. ---- If it was easy, it wouldn't have stumped me for several months... > > You may find it helpful to use "set -x" on the section of the code from > which the error message is originating. ---- I did , that's why I have the PS4 statement in there... but I can't make heads nor tails of the output... recycle_space >>~/.bash_env#7> [[ -n '' ]] >>~/.bash_env#7> [[ -O /tmp/debug_local ]] >>~/.bash_env#11> : /home/law/.bash_env >>~/.bash_env#12> [[ -z 1 ]] >>~/bin/recycle_space#4> export >>'PS4=>>${BASH_SOURCE:+${BASH_SOURCE[0]}}#${LINENO}${FUNCNAME:+(${FUNCNAME[0]})}> >> ' >>~/bin/recycle_space#4> >>PS4='>>${BASH_SOURCE:+${BASH_SOURCE[0]}}#${LINENO}${FUNCNAME:+(${FUNCNAME[0]})}> >> ' >>/home/law/bin/recycle_space#7> _prgpth=/home/law/bin/recycle_space >>/home/law/bin/recycle_space#7> _prg=recycle_space >>/home/law/bin/recycle_space#7> _prgdr=/home/law/bin >>/home/law/bin/recycle_space#8> [[ -z /home/law/bin ]] >>/home/law/bin/recycle_space#8> [[ /home/law/bin == . ]] >>/home/law/bin/recycle_space#8> [[ recycle_space == /home/law/bin ]] >>/home/law/bin/recycle_space#9> export >>PATH=/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 >>/home/law/bin/recycle_space#9> >>PATH=/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 >>/home/law/bin/recycle_space#11> shopt -s expand_aliases extglob sourcepath >>xpg_echo >>/home/law/bin/recycle_space#11> set -o pipefail >>/home/law/bin/recycle_space#13> echo lib/Util/needroot.shh lib/Util/needroot.shh >>/home/law/bin/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 /home/law/bin/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 >>#25(include)> Ls=/usr/bin/ls >>#32(include)> m1='Space Consumed in Recycle bins:' .... You can see _FPATH being constructed from PATH and saved in _SPATH... you can also see the div/0 at line 7 but it's not in the source code. i.e. noticed the output of "-x" has 'include' in parens -- that's include the function. not the file (there was a reason for a more complicated PS4 statement). @ line 9 in the function there is: if [[ -z ${_INC["$fnc"]:-} ]]; then ... and "$fnc" = lib/Utils/needroot.shh -- i.e. it's acting like it is evaluating "$fnc" without the double quotes -- and treating it like an integer expression. But _INC is a *HASH* (not a numeric) array... Could that be what is happening?