Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | None | 0 0
  1. argument=1
  2.  
  3.  
  4. for n in "$@"
  5. do
  6.  
  7. if [ -e $n ] 2>'/dev/null'
  8. then
  9.         echo "Argument #$argument: nespravny vstup"
  10.     ((++argument))
  11.     continue
  12. fi
  13.  
  14. echo "$n" | egrep "^(-)?[[:digit:]]*$" >'/dev/null'
  15. if [ $? -eq 0 ]
  16. then
  17.     #je to cislo
  18.    
  19.     if [ $n -eq 0 ]
  20.     then
  21.         #0
  22.         echo "Argument #$argument: 1"
  23.         ((++argument))
  24.         continue
  25.     fi 
  26.    
  27.     if [ $n -lt 0 ]
  28.     then
  29.         #0>
  30.         echo "Argument #$argument: nedefinovano"
  31.         ((++argument))
  32.         continue
  33.     fi
  34.  
  35.     if [ $n -gt 0 ]
  36.     then
  37.         #1 2 3
  38.         fact=1
  39.         for((i=1;i<=n;++i))
  40.         do 
  41.             ((fact*=i))
  42.         done
  43.  
  44.         echo "Argument #$argument: $fact"
  45.         ((++argument))
  46.         continue
  47.     fi
  48.  
  49.  
  50.  
  51. else
  52.     #nie je to cislo
  53.         echo "Argument #$argument: nespravny vstup"
  54.         ((++argument))
  55.         continue
  56. fi
  57.  
  58.  
  59. done
  60.  
  61. exit $#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement