TechQA.

Linked Questions

  • /dev/urandom maximum size
  • block allocation in unixFreeBSD
  • Display hidden files command
  • why we need COW bit, when reference bit is sufficient?
  • about PATH variable UNIX
  • How do I use my pager (more/less) on error output only
  • Unix Script reading a specific line and position
  • Unix: How to check permissions of a specific directory?
  • When I run "who am i" at a UNIX prompt, what does "tty" and "ttys" stand for?
  • What does the $SHELL command do besides output the shell when I type it at the command prompt?
  • fiding the used and free disk space in percentage by using unix
  • File format of spool file
  • Good book to learn Unix API?
  • Solaris. xterm display problem
  • What to include when teaching a UNIX course?

Popular Questions

  • Partially applied generic function "cannot be cast to Nothing"
  • Peek and Pop not an option
  • Run JIRA in port 80 as root
  • Agar.io style ripple effect for canvas arcs
  • What is the difference between [ValidateModel] and a check of valid state in ASP.NET?
  • Passing shared_ptr to std::function (member function)
  • UWP location tracking even when the app was suspended
  • Docker – fix service IP addresses
  • Dynamic partition in hive
  • How to enable Indications on Client Configuration descriptor from iOS8

shell script to print sum of digits of the given num.In case of negative num is given as input, display Not a positive num as o/p

Asked by Basavaraj At 11 May at 16:05

I'm getting the proper output, but only for positive inputs.

read n
g=$n
s=0
k=
if [ $n -gt 0 ] ; then echo "Not a positive number"
else
    while [ $n -gt 0 ]
       do
          k=$CC $n % 10 ))
          n=$CC $n / 10 ))
          s=$(C $s + $k ))
       done
echo "Sum of digit for given number is $s"
fi
unix
Original Q&A

0 Answers

Related Questions

  • Removing only my files in Unix
  • To check whether script is running for every 5 mins
  • killall on process of same name
  • Exit status of ping command
  • How do you get a / into a filename?
  • What are the well-known UIDs?
  • UNIX Command to recursively change permissions on directories?
  • comparing files
  • How to find the return value of last executed command in UNIX?
  • Script to recursively look for a file on ftp server until it found
  • problem with using wildcards in case statement in unix?
  • PATH and programmatic usage?
  • How to pass the file name dynamically to awk when awk is used in command substitution to build the shell array?
  • Changing environment variable in UNIX
  • I have a file with all the iptable settings. How do I load this into my server?
  • Privacy
  • Terms
  • Cookies