114k views
0 votes
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.

User Natasha
by
3.9k points

1 Answer

3 votes

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( )

Step-by-step 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.

User Jitender Chaudhary
by
4.6k points