I am trying to detect armstrong numbers with this code:
declare -i INPUT=$1
arr=($(fold -w1 <<< "$INPUT"))
for index in "${!arr[@]}"
do
armstrong_sum+=$((${arr[index]}**${#arr[@]}))
done
echo "$armstrong_sum"
Commands to run the code: ./armstrong_sum 9
, armstrong_sum 10
and ./armstrong_sum 153
Output: 9
, 10
and 112527
Expected output: 9
, 1
and 153
An armstrong number is a number that is the sum of its own digits each raised to the power of number of digits
More importantly I want to be able to debug the script myself. Not exactly sure how one debugs in bash. Like get type of operand and see pause iteration at each step
1^3 + 5^3 + 3^3 = 153
. This my expected output, i.e an armstrong number – HarshvardhanSharma Dec 07 '18 at 03:50