Monday, December 12, 2022

Write a shell script to print all the multiplication tables (up to 10) between two given numbers

#!/bin/bash
echo "Enter first number"
read first
echo "Enter Second number"
read second

for ((i=first;i<=second;i++))
do
for((j=1;j<=10;j++))
do
echo  "$i * $j =  $((i*j))"
done

done

 

 using an one liner

 

read -rep $'Enter value of first\n' first && read -rep $'Enter value of second\n' second && for i in $(seq $first $second); do for j in $(seq 1 10); do echo "$i*$j=$((i*j))"; done;done

No comments:

Post a Comment