fork download
  1. #!/bin/bash
  2. # your code goes here
  3.  
  4. echo "enter a number"
  5. read n
  6.  
  7. if [ "$n" -lt 1 ]; then
  8. echo "factorial is not defined for negative numbers"
  9. exit
  10. fi
  11. fact=
  12. i="$n"
  13.  
  14. while [ "$i" -gt 1 ]; do
  15. fact=$((fact * i))
  16. i=$((i - 1))
  17. done
  18.  
  19. echo "the factorial of the given number is $fact"
Success #stdin #stdout #stderr 0.01s 5272KB
stdin
Standard input is empty
stdout
enter a number
the factorial of the given number is 
stderr
./prog.sh: line 7: [: : integer expression expected
./prog.sh: line 14: [: : integer expression expected