I have this bash function:
botch_get_prev_cd(){
local dr=$(declare -f cd);
local dr_trimmed="$(tr -d "$dr")"
if [[ "$dr_trimmed" != *"run_botch"* ]]; then
definition_prev_cd="prev_$dr"
echo "$definition_prev_cd";
eval "${definition_prev_cd}"
unset definition_prev_cd # clean up, no reason to leave this string around
export -f prev_cd
fi
}
when I call it, my routine freezes, appears like it's just going into an infinite loop.
When I change my code to this, it works:
botch_get_prev_cd(){
local dr=$(declare -f cd);
if [[ "$dr" != *"run_botch"* ]]; then
definition_prev_cd="prev_$dr"
echo "$definition_prev_cd";
eval "${definition_prev_cd}"
unset definition_prev_cd # clean up, no reason to leave this string around
export -f prev_cd
fi
}
so maybe I don't need to trim the whitespace to check for matching characters? I hope so, because the first function doesn't seem to work, not sure why it seems to go into an infinite loop..
cd
.