Advertisement
razvanth21

SO - Bash Script Test #1

Dec 1st, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.50 KB | None | 0 0
  1. #! /bin/sh
  2.  
  3. if [ $# -lt 3 ]
  4. then
  5.     echo "Usage: $0 <file> <digit> <...>"
  6.     exit
  7. fi
  8.  
  9. if [ $2 -lt 0 -o $2 -gt 9 ]
  10. then
  11.     echo "Second argument must be a digit."
  12.     exit
  13. fi
  14.  
  15. k=0
  16. s=0
  17.  
  18. for n in "${@:2}"
  19. do
  20.     if [ $(($n % 10)) -eq $2 ]
  21.     then
  22.         echo "$n are uc $2"
  23.        
  24.         k=$(($k + 1))
  25.         s=$(($s + $n))
  26.     fi
  27. done
  28.  
  29. aux=$s
  30. c=0
  31.  
  32. while [ $aux -gt 0 ]
  33. do
  34.     aux=$(($aux/10))
  35.     c=$(($c+1))
  36. done
  37.  
  38. if [ -f $1 ]
  39. then
  40.     echo "Suma este $s si are $c cifre" > $1
  41. else
  42.     echo "$1 is not a regular file"
  43. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement