[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
recursive functions in bash
From: |
davedoom |
Subject: |
recursive functions in bash |
Date: |
Wed, 28 Nov 2007 16:30:12 -0800 (PST) |
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#a14016660
Sent from the Gnu - Bash mailing list archive at Nabble.com.
- recursive functions in bash,
davedoom <=