Hi all ,
I have to write a shell script that takes a number as input , like 123
and the output will be 6 ,i.e the output will be the sum of digits of the input.
I have an idea as follows,
echo "123"|fold -1|tr '\n' '+'|bc
But the problem is after " echo "123"|fold -1|tr '\n' '+' " the output is 1+2+3+ which is not working with bc.
Is there is any way to replace the last character of a line to "\n" ???
Thanking You ,
M.Choudhury