Bash shell script to find sum of digits Last Updated : 18 Aug, 2021 Comments Improve Suggest changes Like Article Like Report Given a number Num, find the sum of digits of the number.Examples: Input : 444 Output : sum of digits of 444 is : 12 Input : 34 Output : sum of digits of 34 is : 7 Approach: 1. Divide the number into single digits 2. Find the sum of digits . Bash # !/bin/bash # Program to find sum # of digits # Static input of the # number Num=123 g=$Num # store the sum of # digits s=0 # use while loop to # calculate the sum # of all digits while [ $Num -gt 0 ] do # get Remainder k=$(( $Num % 10 )) # get next digit Num=$(( $Num / 10 )) # calculate sum of # digit s=$(( $s + $k )) done echo "sum of digits of $g is : $s" Output: sum of digits of 123 is : 6 Comment More infoAdvertise with us Next Article Bash shell script to find sum of digits M Manish_100 Follow Improve Article Tags : Linux-Unix Shell Script Similar Reads Bash shell script to find if a number is perfect or not In this article, we will discuss how to write a bash script to find if a number is perfect or not. A perfect number is defined as, a positive number that is equal to the sum of its proper divisors. Smallest no is 6 ex= 1,2,3 are divisor of 6 and 1+2+3=6 Method 1: Using While LoopRead the input using 3 min read Shell Script to Display the Digits which are in Odd Position Here given a list of numbers, our task is to find the odd position from the given number. Example: Input: 123456 Output: 135 Explanation: 1, 2, 3 are at odd position. Input: 34567 Output: 357 Explanation: 3, 5, 7 are at odd position. We will have to input a number from the user for a dynamic script. 2 min read Shell script to print table of a given number In this article, we will explore the process of creating a simple yet powerful shell script that takes user input and generates number tables. Number tables are a common mathematical concept used to display the multiples of a given number up to a specified limit. We will illustrate this process with 2 min read Shell script to convert binary to decimal Binary and decimal are two fundamental number systems used in computing. While humans typically interact with decimal numbers (0-9), computers internally store and process data using binary digits (0s and 1s). Converting between these systems is often necessary when working with computer programs or 5 min read Shell Script to Validate Integer Input Here we are going to see a shell script which validates an integer. We are going to display whether the input entered is an integer or an invalid input. Approach: Take input from the user.Store the input of any variableNow we are going to trim the input in such a way that all the -(minus) or +(plus) 1 min read Shell Script To Check For a Valid Floating-Point Value User Input can be hectic to manage especially if it's about numbers. Let's say you wanted to perform mathematical calculations in your app or script. It's not hard to say that it will have to deal with floating-point numbers. It's easy in many statically typed programming languages but if it has to 4 min read Looping Statements | Shell Script Looping Statements in Shell Scripting: There are total 3 looping statements that can be used in bash programming Table of Content `while` statement in Shell Script in Linux`for` statement in Shell Script in Linux`until` statement in Shell Script in LinuxExamples of Looping StatementsTo alter the fl 10 min read Array Basics Shell Scripting | Set 2 (Using Loops) It is recommended to go through Array Basics Shell Scripting | Set-1 Introduction Suppose you want to repeat a particular task so many times then it is a better to use loops. Mostly all languages provides the concept of loops. In Bourne Shell there are two types of loops i.e for loop and while loop. 3 min read Shell Script Program to Demonstrate the '$#' Variable In Linux, if we want to count the total number of arguments that are passed to the specific script then we can use the "$#" variable. This variable stores the total count of arguments, the program properly tracks and reports the number of arguments passed at the runtime of the script. Along with thi 5 min read Bash program to check if the Number is a Palindrome Given a number num, find whether the given number is palindrome or not using Bash Scripting. Examples: Input : 666 Output : Number is palindrome Input : 45667 Output : Number is NOT palindrome Approach To find the given number is palindrome just check if the number is same from beginning and the end 1 min read Like