Created
August 1, 2017 10:08
-
-
Save akhlopiachyi/b6a272f70e2250e8a92cb18fc1b61331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ex01/ex01.sh b/ex01/ex01.sh | |
new file mode 100644 | |
index 0000000..4a4fe75 | |
--- /dev/null | |
+++ b/ex01/ex01.sh | |
@@ -0,0 +1,7 @@ | |
+#!/bin/bash | |
+ | |
+if [[ $# == 0 ]]; then | |
+ echo "Hello, World!" | |
+else | |
+ echo "Hello, $@!" | |
+fi | |
diff --git a/ex02/ex02.sh b/ex02/ex02.sh | |
new file mode 100755 | |
index 0000000..c41441c | |
--- /dev/null | |
+++ b/ex02/ex02.sh | |
@@ -0,0 +1,13 @@ | |
+#!/bin/bash | |
+ | |
+count="" | |
+for n in $@ | |
+do | |
+ count=$(ls -R | grep "$n") | |
+ if [ -z "$count" ]; then | |
+ echo "the searched PATH is unexisting" | |
+ | |
+ else | |
+ echo "$count" | |
+ fi | |
+ done | |
diff --git a/ex03/ex03.sh b/ex03/ex03.sh | |
new file mode 100755 | |
index 0000000..b54f1cf | |
--- /dev/null | |
+++ b/ex03/ex03.sh | |
@@ -0,0 +1,46 @@ | |
+#!/usr/bin/env bats | |
+ declare -a array1 | |
+ declare -a array2 | |
+ declare -a array3 | |
+ | |
+ a1=0 | |
+ a2=0 | |
+ a3=0 | |
+ | |
+ i=1 | |
+ | |
+ if [ -z "$4" ];then | |
+ exit 1; | |
+ fi | |
+ | |
+ while read line; do | |
+ if [ "$(echo $line | grep -io $2)" == $2 ];then | |
+ array1[$a1]=$i; | |
+ (( a1=a1+1 )) | |
+ fi | |
+ if [ "$(echo $line | grep -io $3)" == $3 ];then | |
+ array2[$a2]=$i; | |
+ (( a2=a2+1 )) | |
+ fi | |
+ if [ "$(echo $line | grep -io $4)" == $4 ];then | |
+ array3[$a3]=$i; | |
+ (( a3=a3+1 )) | |
+ fi | |
+ ((i=i+1)); | |
+ done < $1 | |
+ | |
+ echo $2 $a1 | |
+ i=0 | |
+ for i in "${array1[@]}" ; do | |
+ echo "$i" | |
+ done | |
+ | |
+ echo $3 $a2 | |
+ for i in "${array2[@]}" ; do | |
+ echo "$i" | |
+ done | |
+ | |
+ echo $4 $a3 | |
+ for i in "${array3[@]}" ; do | |
+ echo "$i" | |
+ done | |
diff --git a/ex04/ex04.sh b/ex04/ex04.sh | |
new file mode 100755 | |
index 0000000..ea22093 | |
--- /dev/null | |
+++ b/ex04/ex04.sh | |
@@ -0,0 +1,26 @@ | |
+#!/bin/bash | |
+ | |
+file=$2 | |
+file_string=$1 | |
+ | |
+o=0 | |
+c=1 | |
+ | |
+if [ -z "$1" ] || [ -z "$2" ];then | |
+ exit 1 | |
+fi | |
+ | |
+while read line; do | |
+ if [ "$o" -eq "0" ] && [ "$(echo $line | grep -io $file_string)" == $file_string ];then | |
+ find $file | |
+ (( o++ )) | |
+ fi | |
+ if [ "$(echo $line | grep -io $file_string)" == $file_string ];then | |
+ echo $c | |
+ fi | |
+ (( c++ )) | |
+done < $file | |
+ | |
+if [ "$o" -eq 0 ];then | |
+ exit 1 | |
+fi | |
diff --git a/ex05/ex05.sh b/ex05/ex05.sh | |
new file mode 100755 | |
index 0000000..fbf2594 | |
--- /dev/null | |
+++ b/ex05/ex05.sh | |
@@ -0,0 +1,53 @@ | |
+#!/bin/bash | |
+f=0 | |
+sum=0 | |
+counter=0 | |
+for i in $@ | |
+do | |
+ if [[ $i =~ ^\-{1}[a-z]+$ ]] || [[ $i =~ ^\-{1}[A-Z]+$ ]]; then | |
+ (( counter=counter+1 )) | |
+ fi | |
+done | |
+if [[ $counter != 1 ]] ; then | |
+ echo "Error.." | |
+ exit 1 | |
+fi | |
+case "$1" in | |
+-s) | |
+ for i in $@ | |
+ do | |
+ (( sum=sum+i )) | |
+ done | |
+ ;; | |
+-e) | |
+ for i in $@ | |
+ do | |
+ (( t=$i%2 )) | |
+ if [[ $t == 0 ]]; then | |
+ (( sum=sum+i )) | |
+ fi | |
+ done | |
+ ;; | |
+-m) | |
+ for i in $@ | |
+ do | |
+ (( sum=sum+i )) | |
+ done | |
+ (( sum=sum/($#-1) )) | |
+ ;; | |
+-o) | |
+ for i in $@ | |
+ do | |
+ (( t=$i%2 )) | |
+ if [[ $t != 0 ]]; then | |
+ (( sum=sum+i )) | |
+ fi | |
+ done | |
+ ;; | |
+*) | |
+ echo "Error.." | |
+ exit 1 | |
+ ;; | |
+esac | |
+ | |
+echo $sum | |
diff --git a/ex06/ex06.sh b/ex06/ex06.sh | |
new file mode 100755 | |
index 0000000..b35676b | |
--- /dev/null | |
+++ b/ex06/ex06.sh | |
@@ -0,0 +1,9 @@ | |
+#!/bin/bash | |
+ | |
+map() { | |
+ function=$1 | |
+ shift | |
+ for i in $@; do | |
+ $function $i | |
+ done | |
+} | |
diff --git a/ex07/ex07.sh b/ex07/ex07.sh | |
new file mode 100755 | |
index 0000000..d198088 | |
--- /dev/null | |
+++ b/ex07/ex07.sh | |
@@ -0,0 +1,7 @@ | |
+#!/bin/bash | |
+ | |
+if [ -z $1 ] || [[ $1 < "1" ]]; then | |
+ exit 1 | |
+else | |
+ head -n $1 resources/surnames.txt | sed '/Q-Chem/d' | sed 's/-//' | sed 's/\.//' | |
+fi | |
diff --git a/ex07/resources/surnames.txt b/ex07/resources/surnames.txt | |
new file mode 100644 | |
index 0000000..f53c4de | |
--- /dev/null | |
+++ b/ex07/resources/surnames.txt | |
@@ -0,0 +1,44 @@ | |
+Q-Chem - SMITH - 10434747. | |
+Q-Chem - JONES - 5628368. | |
+BROWN - 5429595. | |
+JOHNSON - Q-Chem - 4628295 | |
+WILLIAMS - 4173254. | |
+MILLER - 3391134. | |
+TAYLOR - 3337476. | |
+WILSON - 3299960. | |
+DAVIS - 3212807. | |
+WHITE - 2881963. | |
+CLARK - 2809547. | |
+HALL - Q-Chem - 2664037. | |
+THOMAS - 265680 - Q-Chem. | |
+THOMPSON - 2394676. | |
+MOORE - 2331862. | |
+HILL - Q-Chem - 2299107. | |
+WALKER - 2196039. | |
+ANDERSON - Q-Chem - 2183487. | |
+WRIGHT - 2101785. | |
+MARTIN - 2089438. | |
+WOOD - 2074728. | |
+ALLEN - 2041560. | |
+ROBINSON - Q-Chem - 1958046. | |
+LEWIS - 1921163. | |
+SCOTT - 1920172. | |
+YOUNG - 1911430. | |
+JACKSON - Q-Chem - 1906828. | |
+ADAMS - 1900366. | |
+TRYNISKI - Q-Chem - 1880486. | |
+GREEN - Q-Chem - 1858374. | |
+EVANS - 1841052. | |
+KING - 1838171. | |
+BAKER - 1815071. | |
+JOHN - 1808705. | |
+HARRIS - 1730532. | |
+ROBERTS - 1715373. | |
+CAMPBELL - 175100. | |
+JAMES - 1606594. | |
+Q-Chem - STEWAR - 1564485. | |
+LEE - 1505129. | |
+COUNTY - 1499297. | |
+TURNER - 1491163. | |
+PARKER - 1490731 - Q-Chem. | |
+COOK - 1457076. | |
diff --git a/ex08/ex08.sh b/ex08/ex08.sh | |
new file mode 100755 | |
index 0000000..74e5554 | |
--- /dev/null | |
+++ b/ex08/ex08.sh | |
@@ -0,0 +1,47 @@ | |
+#/bin/bash | |
+declare -a array | |
+array=( [0]=0 [1]=0 [2]=0 [3]=0 [4]=0 [5]=0 [6]=0 [7]=0 [8]=0 [9]=0 ) | |
+if [[ "$#" != 1 ]]; then | |
+ echo "Too many(few) arguments" | |
+ exit 1 | |
+fi | |
+if [[ ! -f $1 ]]; then | |
+ echo "Error.." | |
+ exit 1 | |
+fi | |
+while read -n1 c; do | |
+ if [[ $c =~ ^[0-9]+$ ]]; then | |
+ case "$c" in | |
+ 1) | |
+ (( array[1]=array[1]+1 )) | |
+ ;; | |
+ 2) | |
+ (( array[2]=array[2]+1 )) | |
+ ;; | |
+ 3) | |
+ (( array[3]=array[3]+1 )) | |
+ ;; | |
+ 4) | |
+ (( array[4]=array[4]+1 )) | |
+ ;; | |
+ 5) | |
+ (( array[5]=array[5]+1 )) | |
+ ;; | |
+ 6) | |
+ (( array[6]=array[6]+1 )) | |
+ ;; | |
+ 7) | |
+ (( array[7]=array[7]+1 )) | |
+ ;; | |
+ 8) | |
+ (( array[8]=array[8]+1 )) | |
+ ;; | |
+ 9) | |
+ (( array[9]=array[9]+1 )) | |
+ ;; | |
+ 0) (( array[0]=array[0]+1 )) | |
+ ;; | |
+ esac | |
+ fi | |
+done < "$1" | |
+echo "${array[0]} zeroes, ${array[1]} ones, ${array[2]} twoes, ${array[3]} threes, ${array[4]} fours, ${array[5]} fives, ${array[6]} sixs, ${array[7]} sevens, ${array[8]} eights, ${array[9]} nines" | |
diff --git a/ex09/ex09.sh b/ex09/ex09.sh | |
new file mode 100755 | |
index 0000000..3afc0ee | |
--- /dev/null | |
+++ b/ex09/ex09.sh | |
@@ -0,0 +1,16 @@ | |
+#!/bin/bash | |
+ | |
+pattern=$( | |
+case "$1" in | |
+ -e|--email) | |
+ echo '^[a-zA-Z0-9]\+@[a-zA-Z0-9]\+\.[a-z]\{2,\}' | |
+ ;; | |
+ -u| --url) | |
+ echo 'https://[^ >]*' | |
+ ;; | |
+ *) | |
+ echo 'Error..' | |
+ ;; | |
+esac) | |
+ | |
+grep "$pattern" $2 | |
diff --git a/ex10/ex10.sh b/ex10/ex10.sh | |
new file mode 100755 | |
index 0000000..369c718 | |
--- /dev/null | |
+++ b/ex10/ex10.sh | |
@@ -0,0 +1,8 @@ | |
+#!/bin/bash | |
+if [[ ! -f $1 ]]; then | |
+ exit 1 | |
+fi | |
+for i in $@ | |
+do | |
+echo "$(awk 'END {print NR} ' $i) $i" | |
+done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment