Advertisement
mbojmaliev

Командни процедури: Задача 3 [OS]

May 19th, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.94 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function areSame()
  4. {
  5.  
  6. file1=`cat $1`
  7. file2=`cat $2`
  8.  
  9. if [ "$file1" = "$file2" ]; then
  10. echo "true"
  11. else
  12. echo  "false"
  13. fi
  14. }
  15.  
  16.  
  17. #ako ne se prosledeni site argumenti
  18. if [ $# -lt 3 ]; then
  19. echo "USAGE: `basename $0` fromDirectory toDirectory diplicates"
  20. exit 1
  21. fi
  22.  
  23. #ako prviot argument ne e direktorium
  24. if [ ! -d $1 ]; then
  25. echo "First argument is not a directory"
  26. exit 1
  27. fi
  28.  
  29. #ako postoi destinaciskiot argument
  30. if [ -d $2 ]; then
  31. rm -rf $2
  32. fi
  33.  
  34. #da go kreirame bezuslovno
  35. mkdir $2
  36.  
  37. function prebaraj()
  38. {
  39.  
  40. for file in `ls $1`
  41. do
  42. file="$1/$file"
  43. if [ -f $file ]; then
  44.  
  45. novoIme=`readlink -f $file | sed 's/\//__/g'`
  46. echo $novoIme
  47. cp $file "$2/$novoIme"
  48.  
  49. for sekojFile in `ls $2`
  50. do
  51. sporedba=`areSame $file "$2/$sekojFile"`
  52. if [ "$sporedba" = "true" ]; then
  53. echo "$file i $sekojFile imaat isti sodrzini" >> $3
  54. fi
  55. done
  56.  
  57. echo $file
  58. elif [ -d $file ]; then
  59. prebaraj $file $2
  60. fi
  61. done
  62. }
  63. prebaraj $1 $2 $3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement