Write a bash script HW4p2.sh to print out the list of numbers between 0 to 100 (including 0 and 100) that are divisible by both 3 and 5. You must create a bash function inside the script to check the divisibility by 3 and 5.

Respuesta :

Answer:

#!/bin/bash

function number_div( ) {

   for i in {0. .100};

   do

   if (( $i % 3 == 0 ))

   then

   echo $i

   elif (( $i % 5 == 0 ))

   then

   echo $i

   else

   echo "Number not divisible by 3 and 5"

   fi;

   done

}

number_div( )

Explanation:

The bash script is saved as "HW4p2.sh" and executed as "./HW4p2.sh". This code would print all and only numbers divisible by 3 or 5.