SHARE
TWEET

SO - Bash Script Test #1

razvanth21 Dec 1st, 2018 (edited) 11 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top