Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Bash Shell Online

# Name: Jerry Hook
# Serial Number: 25
# Assignment Number: 1
# Due Date: 02/18/19

echo "The function of this script is to:"
echo "1. Display the numbers."
echo "2. Add and multiply 3 numbers."
echo "3. Find all odd and even numbers between 1 and the first argument."
echo "4. Indicate whether the numbers entered are one-digit numbers, two-digit numbers or three-digit numbers."
echo "5. Display all prime numbers between 1 and the second number."
echo

read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
read -p "Enter the third number: " num3
echo

echo "The numbers are $num1 $num2 $num3"
echo

sum=$((num1+num2+num3))

echo "$num1 + $num2 + $num3 = $sum"
echo

prod=$((num1*num2*num3))

echo "$num1 * $num2 * $num3 = $prod"
echo

echo "All odd numbers between 1 and $num1"
echo

for i in {1..num1}
do
    rem=$(($i % 2))
    if [ "$rem" -ne "0" ]; then
            echo -n "$i "
    fi
done
echo

echo "All even numbers between 1 and $num1"
echo

for i in {1..num1}
do
    rem=$(($i % 2))
    if [ "$rem" -eq "0" ]; then
            echo -n "$i "
    fi
done
echo

digits1={#num1}
if [ "digits1" -eq "1" ]; then
    echo "$num1 is a one-digit number"
fi
if [ "digits1" -eq "2" ]; then
    echo "$num1 is a two-digit number"
fi
if [ "digits1" -eq "3" ]; then
    echo "$num1 is a three-digit number"
fi
echo

digits2={#num2}
if [ "digits2" -eq "1" ]; then
    echo "$num2 is a one-digit number"
fi
if [ "digits2" -eq "2" ]; then
    echo "$num2 is a two-digit number"
fi
if [ "digits2" -eq "3" ]; then
    echo "$num2 is a three-digit number"
fi
echo

digits3={#num3}
if [ "digits3" -eq "1" ]; then
    echo "$num3 is a one-digit number"
fi
if [ "digits3" -eq "2" ]; then
    echo "$num3 is a two-digit number"
fi
if [ "digits3" -eq "3" ]; then
    echo "$num3 is a three-digit number"
fi
echo

for i in {1..num2}
do
    flag=0
    for j in {2..num2}
    do
        if[ 'expr $i % $j' -eq 0 ]; then
            flag=1
        fi
    done
        
    if[ flag -eq 0 ]; then
        echo -n "$i "
    fi
done
echo

echo "End of script"
echo
echo "Jerry Hook - 2-18-2019"

exit 0

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.