User:Krunalp28/sandbox

fibonacci 1 --

if [ $# -eq 1 ] then Num=$1 else echo -n "Enter a Number : " read Num fi

Fibonacci {

case $1 in 0|1) printf "$1 " ;; *) echo -n "$(( $(Fibonacci $(($1-2)))+$(Fibonacci $(($1-1))) )) ";; esac }

echo "The Fibonacci sequence for the number $Num is : "

for (( i=0; i<=$Num; i++ )) do Fibonacci $i                    #Calling function Fibonacci done

echo

fib 2

My name is krunal patel

this is program for fibonacci series:::


 * 1) Shell scrpt to generate Fibonacci series using recursion

export MINIDX=2

Fibonacci {   idx=$1 if [ "$idx" -lt "$MINIDX" ]; then echo "$idx" else (( --idx )) term1=$( Fibonacci $idx )

(( --idx )) term2=$( Fibonacci $idx )

echo $(( term1 + term2 )) fi }

echo -n "Enter the number of term : " read MAXTERM

for (( i=0; i<=$MAXTERM; i++ )) do FIBO=$(Fibonacci $i) echo -n "$FIBO " done

echo

exit 0 - The program for printing the patterns is as follows:::::::

echo “Enter the Range” read n k=1 for((i=0;i<=$n;j++))

do for(j=1;j<i;j++) do      echo -n "$k" $k=`expr $k + 1` done echo\ done

---

Removing blank spaces from the string

str=" this is text " echo '$str' | tr -d ' '


 * 1) length of string
 * 2) !/bin/sh
 * 1) !/bin/sh
 * 1) !/bin/sh

echo "Input string=?" read str

leng=`expr length $str` echo "length= "$leng

-

and convert the content to the upper case;;;
 * 1) program for searching file in current dir if present then display else print msg file not exist

clear echo " enter a name " read name if [ -f $name ] then echo -e " the contents are : \n " cat $name tr '[a-z]' '[A-Z]' < $name ls -l $name else echo " file doesnot exist " fi
 * 1) !/bin/bash

Menu driven program for file

clear echo " enter a name " read name if [ -f $name ] then echo -e " the contents are : \n " cat $name tr '[a-z]' '[A-Z]' < $name ls -l $name echo "Enter the word to count" read name1 grep -c $name1 $name
 * 1) !/bin/bash

tac -b $name else echo " file doesnot exist " fi

---

Menu driven program for file

clear i="y" while [ $i = "y" ] do echo "1.search" echo "2.count" echo "3.Creating another file" echo "Enter your choice" read ch case $ch in
 * 1) !/bin/bash

1)echo " enter a name " read name if [ -f $name ] then echo -e " the contents are : \n " cat $name else echo "File does not exists" fi ;;

2)echo "Enter the word to count" read name1 grep -c $name1 $name ;;

3)tac -b $name ;; esac

echo "Do you want to continue?" read i if [ $i != "y" ] then exit fi done