bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: recursive functions in bash


From: davedoom
Subject: Re: recursive functions in bash
Date: Thu, 29 Nov 2007 13:46:45 -0800 (PST)

This code produces the error message:

address@hidden:~$ 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 )  ); }

address@hidden:~$ 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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]