File1:
sdf:
Ishtar:/tmp> more sdf
#!/bin/bash
_prgpth="${0:?}"; _prg="${_prgpth##*}"; _prgdr="${_prgpth%/$_prg}"
[[ -z $_prgdr || $_prg == $_prgdr ]] && $_prgdr="$PWD"
export PATH="$_prgdr/lib:$_prgdr:$PATH"
shopt -s expand_aliases extglob sourcepath ; set -o pipefail
. backtrace.shh
. sdf2
--------------------------------
file2: sdf2
#!/bin/bash
[[ $# -ge 2 ]] && echo weird
--------------------------------
running:
Ishtar:/tmp> sdf
Error executing "[[ $# -ge 2 ]]" in "main"
at "./sdf", line "4" (level=0)
---
So why am I getting a backtrace (and how do I make it put out the right
file)?
I thought rather than something just dying -- it would be nice to know
how it got there... so...backtrace... but the line it is complaining about
is in "sdf2" --- and WTF?... how is testing a number an error that would
cause a
exception?
(if this was running under -e, I presume that if statements that are
false now fail?... )...I thought complex statements were not supposed to
fail
POSIX really F-U'ed on this one... go back to bash 2's "simple
statements"...
having conditional statements fail is going overboard...
I mean it's an explicit check to avoid an error condition...so, of course,
such checks are now errors?!?!?!....ARG *hitting head against wall....***
file:
backtrace.shh:
more /home/law/bin/lib/backtrace.shh
#!/bin/bash
function backtrace {
declare -i level=0
while {
local cmd=$BASH_COMMAND
local fn=${FUNCNAME[level+1]:-}
local src=${BASH_SOURCE[level+1]:-}
local ln=${BASH_LINENO[level]:-}
}; do
[[ -n $fn && -n $src && -n $ln ]] && {
echo " Error executing \"$cmd\" in \"$fn\""
echo " at \"$src\", line \"$ln\" (level=$level)"
level+=1
continue;
}
exit 1
done
}
trap backtrace ERR
set -T