Andrew Courtenay Andrew Courtenay - 1 month ago 12
Bash Question

Interactive shell script - Recursion too deep

I am making an interactive shell script in KSH but keep on getting 'recursion too deep' errors. There is no obvious pattern to it happening, other than the longer I use the script the more likely it gets.

I was previously advised this was because I did not build my menu system from a loop, but I have now done this using 'select'. Here is my menu:

clear

echo "\nDatabase:${HBDB} ClaimId:${CLAIM} TxId:${TRANS} SubsidyId:${SUBS}"
echo "Select your option"
PS3="Option?"

select opt in \
"Input new subsidy row" \
"Change transaction and subsidy id" \
"Change subsidy id only" \
"Show subsidy row details" \
"Exit"

do
case $opt in
"Input new subsidy row")

followUp=$SUPPATH/menuSelect.sh

echo 'Dropping temp table...mcc_ac_tmp_hb9880_${CLAIM}_${TRANS}_${SUBS} ' >> $OUTFILE1

sql $HBDB <<_END_ | sed -n '/DROP/,$p' >> $OUTFILE1

set autocommit on;
\p\g
set lockmode session where readlock = nolock;
\p\g

DROP TABLE mcc_ac_tmp_hb9880_${CLAIM}_${TRANS}_${SUBS};

\p\g

_END_
. $paramSet
break
;;

"Change transaction and subsidy id")
followUp=$SUPPATH/menuSelect.sh

. $transChange

break
;;


"Change subsidy id only")

followUp=$SUPPATH/menuSelect.sh

. $subsChange
break
;;


"Show subsidy row details")
echo "Retrieving details..."
followUp=$SUPPATH/menu1.sh

sql $HBDB <<_END_ | grep '|'

set autocommit on;
\p\g
set lockmode session where readlock = nolock;
\p\g

select claim_id,rent_trans_id,rent_subsidy_id,from_date,pay_amt
from hbrentsubsidy
where claim_id=${CLAIM}
and rent_trans_id=${TRANS}
\p\g
_END_
read
break
;;


"Exit")
exit
;;


*)
echo "ERROR: Invalid selection"
;;
esac
done


. $followUp


Each time an option is selected a function is called, the loop gets broken and the script moves on to a follow up action e.g. chooses another menu to run.

Please let me know if you want more of the whole script

thanks

Answer Source

Problem solved! It does appear there is a limit on the number of times I can source a file - a file operator limit I think. I've got round this by sourcing each file once at the beginning, putting the contents of each file into a function, then calling the function names rather than repeatedly sourcing the files.