Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. Auyez Zhumashev
  2. Alisher Shakhiyev
  3.  
  4. 1. It outputs number between 1 and 10000 that satisfies all three conditions (nr % 5 == 3 && nr % 7 == 4 && nr % 9 == 5).
  5.  
  6. #!/bin/bash
  7.  
  8. MAX=10000 # declare constant 10000
  9.  
  10. for((nr=1; nr<$MAX; nr++)) # for loop from 1 to 10000
  11. do # start of the loop body
  12.  
  13. let "t1 = nr % 5" # calculate nr mod 5 and assign it to vatiable t1
  14. let "t2 = nr % 7" # calculate nr mod 7 and assign it to vatiable t1
  15. let "t3 = nr % 9" # calculate nr mod 9 and assign it to vatiable t1
  16.  
  17. #check if t1 == 3 && t2 == 4 && t3 == 5
  18. if [ "$t1" -eq 3 ] && [ "$t2" -eq 4 ] && [ "$t3" -eq 5 ]
  19. then
  20. break #break if number found
  21. fi
  22. done #finish loop
  23.  
  24. echo "Number = $nr" #print the number
  25. exit 0 #successfully exit the program
  26.  
  27.  
  28. 2. 1)This program lists all files in DIRNAME with their filetypes
  29. 2)finds only those with filetype == FILETYPE
  30. 3)writes them into logfile
  31. 4)outputs the number of scripts
  32.  
  33.  
  34. 3. This script first searches for all java files in "src" directory. Then it takes the second line from each of the files and stores it in the SUM variable. At the end it prints out the result (SUM variable).
  35.  
  36. #---------------SCRIPTS---------------#
  37.  
  38.  
  39. [Self-reproducing Script]
  40. ----------------------------------
  41. 1) #!/bin/bash
  42. scriptname=$(basename "$0")
  43. cat $scriptname >> backup.sh
  44. exit 0
  45.  
  46. 2) #!/bin/bash
  47. scriptname=$(basename "$0")
  48. cat $scriptname » backup.sh
  49. for ((i=1; i<$(($#+1)); i++))
  50. do
  51. eval arg=\$$i # adapted from stackoverflow
  52. cat $arg » $arg.backup
  53. done
  54. exit 0
  55. ----------------------------------
  56.  
  57.  
  58. [While and Until loops]
  59. ----------------------------------
  60. #!/bin/bash
  61.  
  62. array=( Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto )
  63. n=0
  64. limit=9
  65. while [ "$n" -lt "$limit" ]
  66. do
  67. echo ${array[n]}
  68. (( n=n+1 ))
  69. done
  70. exit
  71. -----------------
  72. #!/bin/bash
  73.  
  74. array=( Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto )
  75. n=0
  76. limit=9
  77. until [ "$n" -eq "$limit" ]
  78. do
  79. echo ${array[n]}
  80. (( n=n+1 ))
  81. done
  82. exit
  83. ----------------------------------
  84.  
  85. NOTE: During analyzing first three tasks, we used google to understand the syntax.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement