Advertisement
jovanovski

ОС Лаб4

Mar 26th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.27 KB | None | 0 0
  1. Zadaca 1
  2. ---------------
  3. #!/bin/bash
  4. while getopts "scx:" c; do
  5. case $c in
  6. s)
  7. ls -l|grep "^-..x"|awk '{print $9;}'|grep ".sh\**$"
  8. broj=`ls -l|grep "^-..x"|awk '{print $9;}'|grep ".sh\**$"|wc -l`
  9. if [ $broj -le 0 ]
  10. then
  11. echo "Njama be brat, njama"
  12. fi
  13.  
  14. ;;
  15. c)
  16. ls -l|grep "^-..x"|awk '{print $9;}'|grep ".c\**$"
  17.  
  18. broj=`ls -l|grep "^-..x"|awk '{print $9;}'|grep ".c\**$"|wc -l`
  19. if [ $broj -le 0 ]
  20. then
  21. echo "Njama be brat, njama"
  22. fi
  23.  
  24. ;;
  25. x)
  26. ls -l|grep "^-..x"|awk '{print $9;}'|grep "$OPTARG"
  27.  
  28. broj=`ls -l|grep "^-..x"|awk '{print $9;}'|grep "$OPTARG"|wc -l`
  29. if [ $broj -le 0 ]
  30. then
  31. echo "Njama be brat, njama"
  32. fi
  33.  
  34. ;;
  35. *) echo "nope"
  36. exit 2
  37. esac
  38. done
  39.  
  40.  
  41. -------
  42. Zadaca 2
  43. -------
  44.  
  45. #!/bin/bash
  46.  
  47. if [ $# -lt 2 ]
  48. then
  49. echo "Moras da imas navedeno tocno 2 argumenti, you shmuck"
  50. exit 2
  51. fi
  52.  
  53. if [ !-d $1 ]
  54. then
  55. echo "Ne e validen prviot direktorium"
  56. exit 2
  57. fi
  58.  
  59.  
  60. if [ !-d $2 ]
  61. then
  62. mkdir $2
  63. fi
  64.  
  65. cd $1
  66. ls -l | sed -n '/^-rw-/p' | sed \'s/^-rw-.*:[0-9][0-9] //'
  67. #echo $prom
  68.  
  69.  
  70. --------
  71. Zadaca 3
  72. --------
  73.  
  74. #!/bin/bash
  75.  
  76. if [ $# -le 0 ]
  77. then
  78. echo "glup si"
  79. exit 2
  80. fi
  81.  
  82.  
  83. if [ ! -d $1 ]
  84. then
  85. mkdir $1
  86. else
  87. rm -rf $1
  88. mkdir $1
  89. fi
  90.  
  91. for file in *
  92. do
  93.  
  94. if [ -d $file ]
  95. then
  96. continue
  97. fi
  98.  
  99. ekstenzija=`echo $file | sed 's/^.*\.'//`
  100. echo $ekstenzija
  101.  
  102. cd $1
  103. if [ ! -d $ekstenzija ]
  104. then
  105. mkdir $ekstenzija
  106. fi
  107. cd ..
  108. folder=`echo ${1}/${ekstenzija}`
  109. mv $file $folder
  110.  
  111. done
  112.  
  113. --------
  114. Zadaca 4
  115. --------
  116.  
  117. #!/bin/bash
  118.  
  119. if [ $# -lt 2 ]
  120. then
  121. echo "glup si"
  122. exit
  123. fi
  124.  
  125. if [ ! -f $2 ]
  126. then
  127. touch $2
  128. fi
  129.  
  130. broj=`echo $1`
  131. fajl=`echo $2`
  132.  
  133.  
  134. function fib {
  135.     zbir=`expr $1 + $2`
  136.     if [ $zbir -ge $broj ]
  137.     then
  138.     exit
  139.     fi
  140.    
  141.     echo $zbir >> $fajl
  142.    
  143.     fib $2 $zbir
  144. }
  145.  
  146. fib 1 1
  147.  
  148. --------
  149. Zadaca 5
  150. --------
  151.  
  152. #!/bin/bash
  153.  
  154. argum=`echo $2`
  155. dokj=`echo $1`
  156.  
  157. function grdarekurzija {
  158.     if [ $1 -le $dokj ]
  159.     then
  160.     pret1=`expr $2 \* 2`
  161.     pret2=`expr $pret1 - 1`
  162.     echo "pravam $argum$1$pret2"
  163.     mkdir $argum$1$pret2
  164.     echo "pravam $argum$1$pret1"
  165.     mkdir $argum$1$pret1
  166.     lvl=`expr $1 + 1`
  167.     echo "vlagam vo $argum$1$pret2"
  168.     cd $argum$1$pret2
  169.     grdarekurzija $lvl $pret1
  170.     cd ..
  171.     lvl=`expr $1 + 1`
  172.     pret1=`expr $2 \* 2`
  173.     pret2=`expr $pret1 - 1`
  174.     cd $argum$1$pret1
  175.     grdarekurzija $lvl $pret1
  176.     cd ..
  177.     fi
  178. }
  179.  
  180. grdarekurzija 2 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement