This code produces the error message:
[EMAIL PROTECTED]:~$ function swap_until_one_left { [[ 0 == $( wc -l $1 ) ]] &&
echo "empty file" && exit; [[ 1 == $( wc -l $1 ) ]] && cat $1 && exit; [[ 2
== $( wc -l $1 ) ]] && cat <(tail -1 $1) <(head --lines=-1 $1) && return 0;
cat <(tail -1 $1) <( swap_until_one_left <(head --lines=-1 $1 ) ); }
[EMAIL PROTECTED]:~$ swap_until_one_left simple_test_file
3
malloc: ../bash/subst.c:4135: assertion botched
realloc: start and end chunk sizes differ
-Dave
davedoom wrote:
>
> hi guys,
>
>
> I am trying to learn to write recursive functions in bash. As one of my
> first attempts i wrote this program to emulate the system provided tac
> command:
>
> after playing with it for a good bit, it no longer produces this error
> message:
> malloc: ../bash/subst.c:4135: assertion botched
> realloc: start and end chunk sizes differ
>
> but it doesn't reverse the file. What am i doing wrong? Is there
> something about unix file descriptors I don't understand?
>
> Many Thanks,
> -Dave
>
> function swap_until_one_left
> {
> export NUMBER_OF_LINES=$( wc -l $1 | awk '{ print $1 }' )
> case $NUMBER_OF_LINES in
> 0) echo "empty file"
> exit
> ;;
> 1) cat $1
> exit
> ;;
> 2) cat <(tail -1 $1) <(head --lines=-1 $1)
> exit
> ;;
> *) cat <(tail -1 $1 ) <( swap_until_one_left <(head
> --lines=-1 $1 ) )
> ;;
> esac
>
> }
>
> swap_until_one_left simple_test_file
>
>
> P.S. I am pretty sure that no interpretter should ever say malloc:
> ../bash/subst.c:4135: assertion botched and i would like to report it as a
> bug.
>
> Thanks Again.
>
>
>
>
--
View this message in context:
http://www.nabble.com/recursive-functions-in-bash-tf4894246.html#a14035787
Sent from the Gnu - Bash mailing list archive at Nabble.com.