![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| functions | TimHortons | Shell Programming and Scripting | 2 | 04-08-2009 10:41 AM |
| Use of functions | amitrajvarma | Shell Programming and Scripting | 1 | 11-23-2007 06:52 AM |
| ksh functions | scriptingmani | Shell Programming and Scripting | 3 | 07-06-2007 07:15 AM |
| functions in | Raom | Shell Programming and Scripting | 6 | 07-21-2006 03:06 AM |
| Regarding functions | sendhilmani | Shell Programming and Scripting | 2 | 03-24-2006 04:40 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Need a little help with functions
I'm semi new to unix/linux and am trying to convert a program I wrote in C++ to a bash script. It's a program that prints Fibonacci's series. I have found scripts that will do it, but I'm trying persistently to get this one to work. The problem occurs when I try to return a value from the function. I get no return or I have done something wrong within the function itself. Any help would be much appreciated. Here's what I have so far:
#!/bin/bash #Fibonnaci_Series fibonacci () { n=$1 if [ $n -le 1 ] then return $n else l=`fibonacci $((n-1))` r=`fibonacci $((n-2))` return $((l+r)) fi } echo "Enter the limit for Fibonaaci's Series: " read limit for((i=0; i<=$((limit-1)); i++)) do result=$(fibonacci $i) echo "Fibonacci(" $((i+1)) ") = $result" done |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|