#!/bin/bash # Prompt the user to enter a number read -p "Enter a number: " number # Calculate the number of digits in the number num_digits=${#number} # Initialize a variable to store the sum of the digits raised to the power of the number of digits sum=0 # Loop through each digit of the number and add it to the sum after raising it to the power of the number of digits temp=$number while [ $temp -gt 0 ] do digit=$((temp % 10)) sum=$((sum + digit**num_digits)) temp=$((temp / 10)) done # Check if the sum is equal to the original number if [ $sum -eq $number ]; then echo "$number is an Armstrong number." else echo "$number is NOT an Armstrong number." fi Save the script in a file (e.g., armstrong_script.sh) and make it executable using the following command: bash Copy code chmod +x armstrong_script.sh Then, you can run the script and enter a number to check if it is an Armstrong number: bash Copy code ./armstrong_script.sh The script will prompt you to enter a number and then check if it is an Armstrong number or not, without any validation.
Write, Run & Share Bash code online using OneCompiler's Online Bash Shell for free. It's one of the robust, feature-rich Bash shell available over online and getting started with the OneCompiler's Bash Shell is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Bash
. OneCompiler also has reference scripts, where you can look for the sample scripts and start coding.
Bash (Bourne Again Shell) is a shell program written by Brian Fox and is an upgraded version of Bourne Shell program 'sh'.
name="Foo"
echo $name
echo "$name"
echo "${name}"
if [ conditional-expression ]
then
statements
fi
if [ conditional-expression ]
then
statements
else
statements
fi
if [ conditional-expression ]
then
statements
elif [ conditional-expression ]
then
statements
else
statements
fi