≡ Menu

Shell program to read a number and find the sum of digits

{ 9 comments… add one }
  • mahsa November 7, 2012, 7:01 am

    please write shell script to find sum of first $ last digit of number

    • ShanthaKumar June 3, 2013, 1:34 pm

      very late, but here is it ;)

      $ read a && echo $(echo $a | grep -o . | head -1) + $(echo $a | grep -o . | tail -1) |bc

  • kalpana May 28, 2012, 10:00 am

    is this the shell program to find the sum of digits of a number until a single digit is obtained?

  • Poo May 11, 2012, 6:30 am

    Can any1 temme how to do shell program to find the sum of digits of a number until a single digit is obtained ?

  • ruchika March 31, 2012, 6:55 am

    shell script that reads a filename from the command line and changes the name to filename.aa.where aa is the logname of the user

  • ruchika March 31, 2012, 6:53 am

    a shell script to calculate the sum of digits of a 5 digit number which is input through the keyboard

  • jadu saikia December 28, 2008, 6:24 am

    A one liner for sum of digits using sed.

    $ expr $(echo "12334" | sed 's/[0-9]/ + &/g' | sed 's/^ +//g')

    13

    • ShanthaKumar June 3, 2013, 1:41 pm

      echo -n “Sum of the digits is ” && echo $( echo $1 | grep -o . | tr “n” “+” && echo “0”) | bc

  • basant kumar August 26, 2008, 4:07 pm

    please provide more shell script for unix reader..

Security: Are you a robot or human?

Leave a Comment