Pages

Monday 25 February 2019

LIST OF SHELL PROGRAM

/* 1)program to illustrate if  */
#!/bin/bash
echo " enter a value"
read a
echo " enter b value"
read b
if [ $a -ne $b ]
then
    echo "a is not equal to b"
fi

/* 2)program to illustrate if else */
#!/bin/bash
echo "Enter a value"
read a
echo "Enter b value"
read b
if [ $a -eq $b ]
then
 echo "a is equal to b"
else
 echo "a is not equal to b"
fi

/* 3)program to illustrate nested if else */
#!/bin/bash
echo "Enter a value"
read a
echo "Enter b value"
read b
echo "Enter c value"
read c
if [ $a -gt $b  -a $a -gt $c ]
then
     echo "a is big"
elif [ $b -gt $c ]
then
     echo "b is big"
else
     echo "c is big"                       
fi

/* 4)program to find Odd or Even numbers */
#!/bin/bash
echo " enter any no"
read n
x=`expr $n % 2`
if [ $x -eq 0 ]
then
    echo "$n is even"
else
    echo "$n is odd"
fi

/* 5)program to illustrate switch case */
#!/bin/bash
echo "enter 1st value"
read x
echo  "enter 2nd value"
read y
echo "enter 1 adding"
echo "enter 2 sub"
echo "enter 3 mul"
echo "enter 4 quo"
echo "enter 5 rem"
echo "enter 6 exit"
echo "enter * invalid number"
echo "enter u r choice"
read s
case $s in
1)p=`expr $x + $y`
echo "sum =$p"
;;

2)p=`expr $x - $y`
echo "sub=$p"
;;

3)p=`expr $x \* $y`
echo "mul=$p"
;;

4)p=`expr $x / $y`
echo "quo =$p"
;;

5)p=`expr $x % $y`
echo "rem=$p"
;;

6)exit
;;

*)echo "wrong choice"
;;
esac

/* 6) program to find factorial using while*/
#!/bin/bash
echo "enter any  number"
read n
fact=1
while [ $n -ne 0 ]
do
fact=`expr $fact \* $n`
n=`expr $n - 1`
done
echo "factorial is : $fact"

/* 6.1)program to find factorial using for*/
#!/bin/bash
fact=1
echo "enter a number"
read n
for (( i=$n; i>=1; i-- ))
do
fact=`expr $fact \* $i`
done
echo "the factorial of $n is $fact"

/* 7)program to illustrate multiplication using while  */
#!/bin/bash
echo "multiplication table"
echo "which table u want"
read n
iter=1
while [ $iter -le 10 ]
do
res=`expr $n \* $iter`
echo $n"*"$iter "=" $res
iter=`expr $iter + 1`
done

/* 7.1)program to illustrate multiplication using for  */
#!/bin/bash
echo "multiplication table"
echo "which table u want"
read n
iter=1
for((  ; $iter < 10 ; ))
do
res=`expr $n \* $iter`
echo $n"*"$iter "=" $res
iter=`expr $iter + 1`
done

/* 8)program to find perfect number using while */
#!/bin/bash
echo enter any number
read n
sum=0
i=1
while [ $i -lt $n ]
do
    x=`expr $n % $i`
    if [ $x -eq 0 ]
    then
    sum=`expr $sum + $i`
    fi
i=`expr $i + 1`
done
if [ $sum -eq $n ]
then
echo number is perfect
else
echo number is not a perfect
fi

/* 8.1)program to find perfect number using for */
#!/bin/bash
echo enter any number
read n
sum=0
i=1
for ((  ;  $i <  $n ; ))
do
    x=`expr $n % $i`
    if [ $x -eq 0 ]
    then
    sum=`expr $sum + $i`
    fi
i=`expr $i + 1`
done
if [ $sum -eq $n ]
then
echo number is perfect
else
echo number is not a perfect
fi

/* 9)program to find prime number using while  */
#!/bin/bash
echo "enter any number"
read n
c=0
i=1
while [ $i -le $n ]
do
 x=`expr $n % $i`
 y=`expr $n % $n`
 if [ $x -eq 0 -a $y -eq 0 ]
 then
 c=`expr $c + 1`
 fi
 i=`expr $i + 1`
done
if [ $c -eq 2 ]
then
echo "$n is a prime number"
else
echo "$n is a not a prime number"
fi

/* 9.1)program to find prime number using for  */
#!/bin/bash
echo "enter any number"
read n
c=0
for (( i=1; i<=$n; i++ ))
do
 x=`expr $n % $i`
 y=`expr $n % $n`
 if [ $x -eq 0 -a $y -eq 0 ]
 then
 c=`expr $c + 1`
 fi
done
if [ $c -eq 2 ]
then
echo "$n is a prime number"
else
echo "$n is a not a prime number"
fi

/* 10)program to reverse the given number using while */
#!/bin/bash
echo "enter any number:"
read n
s=$n
rev=0
while [ $n -gt 0 ]
do
rem=`expr $n % 10`
n=`expr $n / 10`
rev=`expr $rev \* 10 + $rem`
done
echo "$s reverse number  is $rev"

output:

/* 10.1)program to reverse the given number using for */
#!/bin/bash
echo "enter any number:"
read n
s=$n
rev=0
for ((  ;  $n > 0 ; ))
do
rem=`expr $n % 10`
n=`expr $n / 10`
rev=`expr $rev \* 10 + $rem`
done
echo "$s reverse number  is $rev"

output:


/* 11)program to illustrate sequentional for  */
for i in $(seq 1 2 10)
do
echo $i
done

/* 12)program to illustrate sequentional for  */
for i in $(seq 10)
do
echo $i
done

/* 13)program to illustrate hi and bye  */

hi()
{
 echo "welcome to unix"
}
bye()
{
date
ls -l
banner  ram is a boy
cowsay sita is a girl
}

output:


Thursday 21 February 2019

Banker's algorithm


Banker's algorithm
The Banker algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra, that tests for safety by simulating the allocation for predetermined maximum possible amounts of all resources, then makes an “safe-state” check to test for possible activities, before deciding whether allocation should be allowed to continue.
For the Banker's algorithm to work, we need to know three things:
    • How much of each resource each process could possibly request[MAX]
    • How much of each resource each process is currently holding[ALLOCATED]
    • How much of each resource the system currently has available[AVAILABLE]
Implementation :Let ‘n’ be the number of processes in the system and ‘m’ be the number of resources types.
Available : 
  • It is a 1-d array of size ‘m’ indicating the number of available resources of each type.
  • Available[ j ] = k means there are ‘k’ instances of resource type Rj
Max :
  • It is a 2-d array of size ‘n*m’ that defines the maximum demand of each process in a system.
  • Max[ i, j ] = k means process Pi may request at most ‘k’ instances of resource type Rj.
Allocation :
  • It is a 2-d array of size ‘n*m’ that defines the number of resources of each type currently allocated to each process.
  • Allocation[ i, j ] = k means process Pi is currently allocated ‘k’ instances of resource type Rj
Need :
  •  It is a 2-d array of size ‘n*m’ that indicates the remaining resource need of each process.
  • Need [ i,  j ] = k means process Pi currently need ‘k’ instances of resource type Rj
    for its execution.
  • Need [ i,  j ] = Max [ i,  j ] – Allocation [ i,  j ]

Note:

Allocationi specifies the resources currently allocated to process Pi a
Needi specifies the additional resources that process Pi may still request to complete its task.
Banker’s algorithm consist of Safety algorithm and Resource request algorithm


Safety Algorithm
The algorithm for finding out whether or not a system is in a safe state can be described as follows:
1) Let Work and Finish be vectors of length ‘m’ and ‘n’ respectively.
Initialize: Work = Available
Finish[i] = false; for i=1, 2, 3, 4….n
2) Find an i such that both
a) Finish[i] = false
b) Needi <= Work
if no such i exists goto step (4)
3) Work = Work + Allocation[i]
Finish[i] = true
goto step (2)
4) if Finish [i] = true for all i
then the system is in a safe state
Resource-Request Algorithm
Let Requesti be the request array for process Pi. Requesti [j] = k means process Pi wants k instances of resource type Rj. When a request for resources is made by process Pi, the following actions are taken
1) If Requesti <= Needi
Goto step (2) ; otherwise, raise an error condition, since the process has exceeded its maximum claim.
2) If Requesti <= Available
Goto step (3); otherwise, Pi must wait, since the resources are not available.
3) Have the system pretend to have allocated the requested resources to process Pi by modifying the state as
follows:
Available = Available – Requesti
Allocationi = Allocationi + Requesti
Needi = Needi– Requesti

Program on Bankers algorithm
#include <stdio.h>
#include <stdlib.h>
void main()
{
    int Max[10][10], need[10][10], alloc[10][10];
    int avail[10], completed[10], safeSequence[10];
    int p, r, i, j, process, count=0;
    printf("\nEnter the no of processes : ");
    scanf("%d", &p);
    for(i = 0; i< p; i++)
    completed[i] = 0;
    printf("\nEnter the no of resources : ");
    scanf("%d", &r);
    printf("\nEnter the Max Matrix for each process : ");
    for(i = 0; i < p; i++)
    {
    printf("\nFor process %d : ", i + 1);
    for(j = 0; j < r; j++)
        scanf("%d", &Max[i][j]);
    }
    printf("\nEnter the allocation for each process : ");
    for(i = 0; i < p; i++)
    {
    printf("\nFor process %d : ",i + 1);
    for(j = 0; j < r; j++)
        scanf("%d", &alloc[i][j]);
    }
    printf("\nEnter the Available Resources : ");
    for(i = 0; i < r; i++)
    scanf("%d", &avail[i]);
    for(i = 0; i < p; i++)
    {
      for(j = 0; j < r; j++)
       {
        need[i][j] = Max[i][j] - alloc[i][j];
       }
    }
    do
    {
        printf("\n Max matrix:\tAllocation matrix:\n");
        for(i = 0; i < p; i++)
        {
        for( j = 0; j < r; j++)
            printf("%d ", Max[i][j]);
        printf("\t\t");
        for( j = 0; j < r; j++)
            printf("%d ", alloc[i][j]);
        printf("\n");
        }
        process = -1;
        for(i = 0; i < p; i++)
        {
        if(completed[i] == 0)//if not completed
        {
            process = i ;
            for(j = 0; j < r; j++)
            {
            if(avail[j] < need[i][j])
            {
                process = -1;
                break;
            }
            }
        }
        if(process != -1)
            break;
        }

       if(process != -1)
         {
              printf("\nProcess %d runs to completion!", process + 1);
        safeSequence[count] = process + 1;
        count++;
        for(j = 0; j < r; j++)
        {
            avail[j] += alloc[process][j];
            alloc[process][j] = 0;
            Max[process][j] = 0;
            completed[process] = 1;
        }
        }
    }while(count != p && process != -1);

    if(count == p)
    {
        printf("\nThe system is in a safe state!!\n");
        printf("Safe Sequence : < ");
        for( i = 0; i < p; i++)
        printf("%d ", safeSequence[i]);
        printf(">\n");
    }
    else
        printf("\nThe system is in an unsafe state!!");
}


Single Resource Output:





Multiple Resource Output:



Thursday 14 February 2019

Page Replacement Algorithms - Optimal Page Replacement

Page Replacement Algorithms - Optimal Page Replacement

//program on page replacement alogarthim -optimal 
#include<stdio.h>
main()
{
 int frames[10],n,seq[30],c=0,i,j,nl,x=0,m,k,flag=0,l,mf[10];
 int c1,c2,c3,m1,m2;
 printf("enter number of pages:");
 scanf("%d",&nl);
 printf("\n enter pages:");
 for(i=0;i<nl;i++)
  scanf("%d",&seq[i]);
 printf("\n enter no of frames:");
 scanf("%d",&n);
 for(i=0;i<n;i++)
  frames[i]=-1;
 for(x=0,i=0;x<n;i++)
 {
  for(j=0;j<n;j++)
  {
   flag=0;
   if(seq[i]==frames[j])
   {
     flag=1;
     break;
   }
  }
  if(flag==0)
   {
   frames[x]=seq[i];
   m=i;
   x++;
   c=c+1;
   printf("\n \n");
   for(k=0;k<x;k++)
    printf("\t %d",frames[k]);
   }
 }
  for(i=m+1;i<nl;i++)
  {
   for(j=0;j<n;j++)
   {
    flag=0;
    if(seq[i]==frames[j])
    {
     flag=1;
     break;
    }
   }
   if(flag==0)
   {
    for(k=0;k<n;k++)
    mf[k]=0;
    c1=0;c2=0;c3=0;
    for(j=i+1;j<nl;j++)
    {
     for(k=0;k<n;k++)
     {
      if(frames[k]==seq[j])
      {
       mf[k]=mf[k]+1;
       if(k==0)
         c1=1;
       else if(k==1)
         c2=1;
      else if(k==2)
         c3=1;
      break;
      }
     }
     if(((c1==1)&&(c2==1))||((c2==1)&&(c3==1))||((c3==1)&&(c1==1)))
            break;
    }
    m1=0;
    m2=mf[0];
    for(k=0;k<n;k++)
    {
     if(mf[k]<m2)
     {
      m1=k;
      m2=mf[k];
     }
    }
    frames[m1]=seq[i];
    c=c+1;
    printf("\n \n");
    for(l=0;l<n;l++)
     printf("\t %d",frames[l]);
   }
  }
  printf("\n\n\n the n of pages faults=%d",c);
}



output:

Page Replacement Algorithms - LRU

Page Replacement Algorithms - LRU

//Program on Page Replacement Algorithms - LRU
#include<stdio.h>
void main()
{
 int frames[10],n,seq[30],c=0,i,j,n1,x=0,m,k=0,flag=0,l,fc[10],r;
 printf("\n enter number of pages : ");
 scanf("%d",&n1);
 printf("\n enter the pages : ");
 for(i=0;i<n1;i++)
  scanf("%d",&seq[i]);
 printf("enter the number of frames:");
   scanf("%d",&n);
 for(i=0;i<n;i++)
 {
   frames[i]=-1;
   fc[i]=0;
 }
 for(x=0,i=0;x<n;i++)
 {
  for(j=0;j<n;j++)
  {
   flag=0;
   if(seq[i]==frames[j])
   {
    flag=1;
    k++;
    fc[j]=k;
    break;
   }
  }
  if(flag==0)
  {
   frames[x]=seq[i];
   m=i;
   c=c+1;
   k++;
   fc[x]=k;
   x++;
   printf("\n \n");
   for(l=0;l<x;l++)
    printf("\t %d",frames[l]);
  }
 }
 for(i=m+1;i<n1;i++)
 {
   for(j=0;j<n;j++)
   {
    flag=0;
    if(seq[i]==frames[j])
    {
     flag=1;
     k++;
     fc[j]=k;
     break;
    }
   }
   if(flag==0)
   {
    r=fc[0];
    j=0;
    for(l=1;l<n;l++)
    {
     if(r>fc[l])
     {
      r=fc[l];
      j=l;
     }
    }
    frames[j]=seq[i];
    k++;
    fc[j]=k;
    c=c+1;
    printf("\n \n");
    for(l=0;l<n;l++)
      printf("\t %d",frames[l]);
  }
 }
 printf("\n \n the no of pages faults:%d",c);
}


output:


Page Replacement Algorithms - FIFO

Page Replacement Algorithms - FIFO

When a page fault occurs, the operating system has to choose a page to remove from memory to make room for the page that has to be brought in. The page replacement is done by swapping the required pages from backup storage to main memory and vice-versa. 

The page replacement algorithm is evaluated by running the particular algorithm on a string of memory references and compute the page faults.Referenced string is a sequence of pages being referenced.

Page faults are not errors and are common and necessary to increase the amount of memory available to programs in any operating system that utilizes virtual memory, including Microsoft Windows, Mac OS X, Linux and Unix.

Each operating system uses different page replacement algorithms. To select the particular algorithm, the algorithm with lowest page fault rate is considered.

1.First-In, First-Out page replacement

2.Least recently used page replacement

3.Optimal page replacement algorithm

 Program on FIFO( First-In, First-Out ) page replacement

//Program to illustrate First In First Come Page Replacement Alogarthim
#include<stdio.h>
void main()
{
 int frames[10],n,seq[30],c=0,i,j,n1,x=0,m,k,flag=0,l;
 printf("\n enter the number of pages : ");
 scanf("%d",&n1);
 printf("\n enter the pages : ");
 for(i=0;i<n1;i++)
   scanf("%d",&seq[i]);
 printf("enter the number of frames : ");
   scanf("%d",&n);
 for(i=0;i<n;i++)
   frames[i]=-1;
 for(x=0,i=0;x<n;i++)
 {
   for(j=0;j<n;j++)
   {
     flag=0;
     if(seq[i]==frames[j])
     {
          flag=1;
          break;
     }
   }
 
    if(flag==0)
   {
     frames[x]=seq[i];
     m=i;
     x++;
     c=c+1;
     printf("\n\n");
    for(k=0;k<x;k++)
      printf("\t %d",frames[k]);
   }
  }
  k=0;
  for(i=m+1;i<n1;i++)
  {
   if(k==n)
     k=0;
   for(j=0;j<n;j++)
   {
    flag=0;
    if(seq[i]==frames[j])
    {
      flag=1;break;
    }
   }
   if(flag==0)
   {
    frames[k]=seq[i];
    k++;
    c=c+1;
    printf("\n \n");
    for(l=0;l<n;l++)
     printf("\t %d",frames[l]);
   }
  }
  printf("\n \n the no of page faults = %d",c);
 }

output:

 

Friday 8 February 2019

How to Install VirtualBox Guest Additions on Ubuntu 18.04 Guest / virtual machine


Install VirtualBox Guest Additions on Ubuntu 18.04 Guest / virtual machine




Step 1. Install required packages. Before installing VirtualBox Guest Additions on Ubuntu 18.04 we need to install some required packages. So open the terminal and run the following command.

sudo apt install linux-headers-$(uname -r) build-essential dkms

Step 2. Install Guest Additions using virtual box. In order To install VirtualBox Guest Additions on Ubuntu virtual machine, Got to VirtualBox - select the Devices from VirtualBox host application menu - click Insert Guest Additions CD image.

Step 3. This will open a pop up window and it will ask you to run it. Press Run button (see the picture below) After pressing Run button it will install VirtualBox Guest Additions on Ubuntu 18.04. Press enter to close the window.

Step 4. Shut down your Ubuntu 18.04 Guest.

Step 5. Start Ubuntu 18.04 virtual machine and check if copy and paste works. Finish

Tuesday 5 February 2019

Intoduction to shell programs - control structures


shell programs based on Control Structures 
    1. IF Statement

Syntax:

if [ expression ]
then
Statement(s) to be executed if expression is true
fi

Description:-
The if...fi statement is the fundamental control statement that allows Shell to make decisions and execute statements conditionally.
If expression is a shell command then it would be assumed true if it return 0 after its execution. If it is a boolean expression then it would be true if it returns true.



Example:

#!/bin/sh

a=10
b=20

if [ $a == $b ]
then
echo "a is equal to b"
fi

if [ $a != $b ]
then
echo "a is not equal to b"
fi
This will produce following result:
a is not equal to b

program:
#!/bin/bash
echo -n " enter a value :"
read a
echo -n " enter b value :"
read b

if [ $a -gt $b ]
then
echo "$a is greater then  $b"
fi

if [ $a -lt $b ]
then
echo "$a is less then $b"
fi

if [ $a -ge $b ]
then
echo "$a is  greater then or equal to  $b"
fi

if [ $a -le $b ]
then
echo "$a is less then oe equal to  $b"
fi

if [ $a -eq $b ]
then
echo "$a is equal to $b"
fi

if [ $a -ne $b ]
then
echo "$a is not equal to  $b"
fi
Output:

    1. THE if…else Statement

Syntax:

if [ expression ]
then
Statement(s) to be executed if expression is true
else
Statement(s) to be executed if expression is not true
fi


Description:- The if...else...fi statement is the next form of control statement that allows Shell to execute statements in more controlled way and making decision between two choices.

Example:

If we take above example then it can be written in better way using if...else statement as follows:
#!/bin/sh

a=10
b=20

if [ $a == $b ]
then
echo "a is equal to b"
else
echo "a is not equal to b"
fi
This will produce following result:
a is not equal to b

Program:
#!/bin/bash
echo -n " enter a value :"
read a
echo -n " enter b value :"
read b

if [ $a == $b ]
then
echo "a is equal to  b"
else
echo "a is not equal then b"
fi
Output:


    1. If…elif…fi

Syntax:

if [ expression 1 ]
then
Statement(s) to be executed if expression 1 is true
elif [ expression 2 ]
then
Statement(s) to be executed if expression 2 is true
elif [ expression 3 ]
then
Statement(s) to be executed if expression 3 is true
else
Statement(s) to be executed if no expression is true
fi


Description:- The if...elif...fi statement is the one level advance form of control statement that allows Shell to make correct decision out of several conditions.


Example:

#!/bin/sh

a=10
b=20

if [ $a == $b ]
then
echo "a is equal to b"
elif [ $a -gt $b ]
then
echo "a is greater than b"
elif [ $a -lt $b ]
then
echo "a is less than b"
else
echo "None of the condition met"
fi
This will produce following result:
a is less than b

program:
#!/bin/bash
echo " enter a value:"
read a
echo " enter b value:"
read b
echo " enter c value:"
read c

if [ $a -gt $b -a $a -gt $c ]
then
echo "a is big"
elif [ $b -gt $c ]
then
echo "b is big "
else
echo "c is big"
fi
output:

    1. Case…esac

Syntax:

The basic syntax of the case...esac statement is to give an expression to evaluate and several different statements to execute based on the value of the expression.
The interpreter checks each case against the value of the expression until a match is found. If nothing matches, a default condition will be used.
case word in
pattern1)
Statement(s) to be executed if pattern1 matches
;;
pattern2)
Statement(s) to be executed if pattern2 matches
;;
pattern3)
Statement(s) to be executed if pattern3 matches
;;
esac


Description:- Shell support case...esac statement which handles exactly this situation, and it does so more efficiently than repeated if...elif statements.


Example:

#!/bin/sh

FRUIT="kiwi"

case "$FRUIT" in
"apple") echo "Apple pie is quite tasty."
;;
"banana") echo "I like banana nut bread."
;;
"kiwi") echo "New Zealand is famous for kiwi."
;;
esac
This will produce following result:
New Zealand is famous for kiwi.


Example verified in ubuntu :
echo "enter 1st value"
read x
echo "enter 2nd value"
read y
echo "enter 1 adding"
echo "enter 2 sub"
echo "enter 3 mul"
echo "enter 4 quo"
echo "enter 5 rem"
echo "enter 6 exit"
echo "enter * invalid number"
echo "enter u r choice"
read s
case $s in
1)p=`expr $x + $y`
echo "sum =$p"
;;
2)p=`expr $x - $y`
echo "sub=$p"
;;
3)p=`expr $x \* $y`
echo "mul=$p"
;;
4)p=`expr $x / $y`
echo "quo =$p"
;;
5)p=`expr $x % $y`
echo "rem=$p"
;;
6)exit
;;
*)echo "wrong choice"
;;
esac

program:
#!/bin/bash
echo "enter 1st value"
read x
echo  "enter 2nd value"
read y
echo "enter 1 adding"
echo "enter 2 sub"
echo "enter 3 mul"
echo "enter 4 quo"
echo "enter 5 rem"
echo "enter 6 exit"
echo "enter * invalid number"
echo "enter u r choice"
read s
case $s in
1)p=`expr $x + $y`
echo "sum =$p"
;;

2)p=`expr $x - $y`
echo "sub=$p"
;;

3)p=`expr $x \* $y`
echo "mul=$p"
;;

4)p=`expr $x / $y`
echo "quo =$p"
;;

5)p=`expr $x % $y`
echo "rem=$p"
;;

6)exit
;;

*)echo "wrong choice"
;;
esac


output:

    1. While
Syntax:
while command
do
Statement(s) to be executed if command is true
done
Description:- Here Shell command is evaluated. If the resulting value is true, given statement(s) are executed. If command is false then no statement would be not executed and program would jump to the next line after done statement

Example:

Here is a simple example that uses for loop to span through the given list of numbers:
#!/bin/sh

a=0

while [ $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
This will produce following result:
0
1
2
3
4
5
6
7
8
9

program:
#!/bin/bash
echo "enter any  number"
read n
fact=1
while [ $n -ne 0 ]
do
fact=`expr $fact \* $n`
n=`expr $n - 1`
done
echo "factorial is : $fact"

output:

    1. Loop

Syntax:

for var in word1 word2 ... wordN
do
Statement(s) to be executed for every word.
done

Description:- Here var is the name of a variable and word1 to wordN are sequences of characters separated by spaces (words). Each time the for loop executes, the value of the variable var is set to the next word in the list of words, word1 to wordN.

Example:

Here is a simple example that uses for loop to span through the given list of numbers:
#!/bin/sh

for var in 0 1 2 3 4 5 6 7 8 9
do
echo $var
done
This will produce following result:
0
1
2
3
4
5
6
7
8
9

program:
#!/bin/bash
fact=1
echo "enter a number"
read n
for (( i=$n; i>=1; i-- ))
do
fact=`expr $fact \* $i`
done
echo "the factorial of $n is $fact"

output: