[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Segmentation fault
From: |
Chet Ramey |
Subject: |
Re: Segmentation fault |
Date: |
Wed, 12 Dec 2007 17:36:48 -0500 |
User-agent: |
Thunderbird 2.0.0.9 (Macintosh/20071031) |
seba wrote:
> GNU bash, version 3.2.25(1)-release (i686-pc-linux-gnu)
> Copyright (C) 2005 Free Software Foundation, Inc.
>
> #!/bin/sh
>
> fib() {
> n=$1
> [ $n == 0 -o $n == 1 ] && return $n
> fib $(($n-1))
> ret1=$?
> fib $(($n-2))
> ret2=$?
> return $(($ret1 + $ret2))
> }
>
> for ((i=0;$i<36;i++))
> do
> fib $i
> echo "n=$i=>$?"
> done
You managed to write yourself an infinitely-recursive function, and
eventually ran out of stack space. `==' is a string operator, not a
numeric operator, when used with `['.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
Live Strong. No day but today.
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/
- Segmentation fault, seba, 2007/12/12
- Re: Segmentation fault,
Chet Ramey <=
- Message not available