Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.40 KB | None | 0 0
  1. # Write a shell script that reads a folder name from the keyboard and computes the average
  2. # number of lines from each text file inside it and it’s subfolders.
  3.  
  4. #!/bin/sh
  5. read D
  6. if [ ! -d $D ]
  7. then
  8.     echo $D is not a directory.
  9.     exit 1
  10. fi
  11. s=0
  12. n=0
  13. for fis in `find $D -type f`
  14. do
  15.     l=`grep -c ".*" $fis`
  16.     s=`expr $s + $l`
  17.     n=`expr $n + 1`
  18. done
  19. avg=`expr $s / $n`
  20. echo $avg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement