echo — echo command is used to print the characters on the screen, it echoes back whatever you type after it and strings must be enclosed in “” and variable must be start with $withvariablename. The $ sign tells the interpreter that the user wants to print the actual value stored in the variable.

read —read c command is reading an input and putting it in a variable named c, now that could be anything but we used c here.

function armstrong {} — This is actual function which consists the code for finding the armstrong number.

x=$1 —This tells the program to take the first parameter passed in the function and put it in the variable x.

l=${#x} — This is storing the number of digits in the number that we are passing. x is the variable contains the number that is passed in the function, # tell to count it, $ will take it’s value and put it in the variable l.

r=`expr $x % 10` — The math in shell scripting happens in the form of expr. Note that the expr expression is enclosed with the tick ( ` ) sign and it is not a quote. If you use a quote it will generate an error depending on the type of shell script.

n=$(bc <<< “$r^$l”) — expr does provide us with a lot of mathematical expression calculation ability but it does not provide us to calculate power of a number. So, To get the power of the number I’ve used bc command which is the best command for calculating different mathematical expression. The line suggests that, I am passing two variables $r,$l and using operator ^ which is power operator for bash and I am passing it to bc, which in turn storing the value in variable n.

while is the looping function, and If then else is conditional statements.

if [ $sum -eq $c ] — in bash as the operator we use -eq for equal to, -ne for not equal, -lt for less than, -gt for greater than instead of traditional <,>,==,!=.

The last two lines

result=`armstrong $c`

echo $result

says that armstrong function will take $c variable as the passed variable which will later becomes x inside the function and the result of the calculation of armstrong function will be saved in a variable called result.