Home

CyberKabila

Table Of Contents

shell script to generate fibonacci series
shell script to find wheather a particular year is a leap year or not
shell script to print alternate digits when a 7 digit number is passed as input
shell script to find average of numbers passed as input
shell script to find wheather a given word is palindrome or not
shell script to reverse a inputed string and show it.
shell script to count occurence of a perticular digit in inputted number.
shell script to find even or odd.

Download 42 shell scripts

shell script to generate fibonacci series

#!/bin/bash
#shell script to generate fibonacci series
echo "how many fibonacci numbers do u want "
read limit
a=0
b=1
d=1
echo "-------------------------------------------------------------"
echo -n $a
echo -n " "
while test $d -le $limit 
do
c=`expr ${a} + ${b}`
echo -n $c
echo -n " "
b=$a
a=$c
d=`expr $d + 1`
done

shell script to find wheather a particular year is a leap year or not

#!/bin/bash
#shell script to find wheather a particular year is a leap year or not
echo -n "Enter the year(yyyy) to find leap year :- "
read year
d=`expr $year % 4`
b=`expr $year % 100`
c=`expr $year % 400` 
if [ $d -eq 0 -a $b -ne 0 -o $c -eq 0 ]
then 
echo "year is leap year"
else
echo "not leap year"
fi

shell script to print alternate digits when a 7 digit number is passed as input

#!/bin/bash
#shell script to print alternate digits when a 7 digit number is passed as input
echo -n "Enter a 7 digit number:- "
read number
len=`echo $number | wc -c`
flag=1
while test $flag -le $len
do
echo $number | cut -c$flag
flag=`expr $flag + 2`
done

shell script to find average of numbers given at command line

#Tue May 28 11:12:41 MUT 2002
total=0
count=$#
for i #or u can append ( in $*) to get same result.
do
total=`expr $total + $i`
done
avg1=`expr $total / $count`
avg2=`expr $total % $count`
avg2=`expr $avg2 \* 100 / $count`
echo "The Average is :- $avg1.$avg2"

shell script to find wheather a given word is palindrome or not

#Sun Jun 9 12:06:14 MUT 2002 --By Mukesh
clear
echo -n "enter the name :-"
read name
len=`echo -n $name | wc -c`
echo "Length of the name is :-"$len
while [ $len -gt 0 ]
do
rev=$rev`echo $name | cut -c$len`
len=`expr $len - 1`
done
echo "Reverse of the name is :-"$rev
if [ $name = $rev ]
then echo "It is a palindrome"
else
echo "It is not a palindrome"
fi

shell script to reverse a inputed string and show it.

#!/bin/bash
#shell script to reverse a inputed string and show it.

echo -n "enter the string u want to reverse:-"
read string
len=`echo -n $string |wc -c`
echo "no of character is:- $len"
while test $len -gt 0
do
rev=$rev`echo $string |cut -c $len`
len=`expr $len - 1`
done
echo "the reverse string is:-$rev "

shell script to count occurence of a perticular digit in inputted number.

#!/bin/bash
#shell script to count occurence of a perticular digit in inputted number.

echo -n "enter any number:-"
read number
echo -n "which digit number do u want to count:-"
read digit
len=`echo -n $number |wc -c`
echo "the length of number is:-$len"
count=0
while test $len -gt 0
do
flag=`echo -n $number |cut -c $len`
if test $flag -eq $digit
then
count=`expr $count + 1`
fi
len=`expr $len - 1`
done
echo "|$digit| occured |$count| times in number ($number)"

shell script to find even or odd.

#!/bin/bash
#shell script to find even or odd.

echo -n "enter any integer number to find even and odd :-"
read number
rem=`expr $number % 2`
if test $rem -eq 0
then
echo "number is even"
else
echo "number is odd"
fi

site designed and developed by mukesh and adam

Counter

Hosted by www.Geocities.ws

1