Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Shell Bash Scripting: Assignment & Excercise – 11


Write a Shell Bash Script for check if a provided number is Armstrong or not


Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
s9py
s9py
1 year ago

#Your’s is wrong and works only for 3 digits but this one works flawlessly
#!/bin/bash

read -p “Enter Number:” num

temp=$num
arm=0
count=${#num}

if [ $num -lt 10 ]
then
    echo “$num is armstrong number (1-9)”
else
    while [ $num -gt 0 ]
    do
        rem=$((num%10))
        arm=$((arm + rem**count))
        num=$((num/10))
    done

    if [ $arm -eq $temp ]
    then
        echo “$arm = $temp Armstrong Number!”
    else
        echo “$arm != $temp Not a Armstrong Number!”
    fi
fi

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

1
0
Would love your thoughts, please comment.x
()
x