Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Auyez Zhumashev
- Alisher Shakhiyev
- 1. It outputs number between 1 and 10000 that satisfies all three conditions (nr % 5 == 3 && nr % 7 == 4 && nr % 9 == 5).
- #!/bin/bash
- MAX=10000 # declare constant 10000
- for((nr=1; nr<$MAX; nr++)) # for loop from 1 to 10000
- do # start of the loop body
- let "t1 = nr % 5" # calculate nr mod 5 and assign it to vatiable t1
- let "t2 = nr % 7" # calculate nr mod 7 and assign it to vatiable t1
- let "t3 = nr % 9" # calculate nr mod 9 and assign it to vatiable t1
- #check if t1 == 3 && t2 == 4 && t3 == 5
- if [ "$t1" -eq 3 ] && [ "$t2" -eq 4 ] && [ "$t3" -eq 5 ]
- then
- break #break if number found
- fi
- done #finish loop
- echo "Number = $nr" #print the number
- exit 0 #successfully exit the program
- 2. 1)This program lists all files in DIRNAME with their filetypes
- 2)finds only those with filetype == FILETYPE
- 3)writes them into logfile
- 4)outputs the number of scripts
- 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).
- #---------------SCRIPTS---------------#
- [Self-reproducing Script]
- ----------------------------------
- 1) #!/bin/bash
- scriptname=$(basename "$0")
- cat $scriptname >> backup.sh
- exit 0
- 2) #!/bin/bash
- scriptname=$(basename "$0")
- cat $scriptname » backup.sh
- for ((i=1; i<$(($#+1)); i++))
- do
- eval arg=\$$i # adapted from stackoverflow
- cat $arg » $arg.backup
- done
- exit 0
- ----------------------------------
- [While and Until loops]
- ----------------------------------
- #!/bin/bash
- array=( Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto )
- n=0
- limit=9
- while [ "$n" -lt "$limit" ]
- do
- echo ${array[n]}
- (( n=n+1 ))
- done
- exit
- -----------------
- #!/bin/bash
- array=( Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto )
- n=0
- limit=9
- until [ "$n" -eq "$limit" ]
- do
- echo ${array[n]}
- (( n=n+1 ))
- done
- exit
- ----------------------------------
- NOTE: During analyzing first three tasks, we used google to understand the syntax.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement