diff --git a/ex01/hello_world.sh b/ex01/hello_world.sh new file mode 100755 index 0000000..52015c4 --- /dev/null +++ b/ex01/hello_world.sh @@ -0,0 +1,8 @@ +#!/bin/bash +if [ -z $1 ]; +then + echo "Hello, World!" +else + echo "Hello, $1!" +fi + diff --git a/ex02/ex02.sh b/ex02/ex02.sh new file mode 100755 index 0000000..2bccbe0 --- /dev/null +++ b/ex02/ex02.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +for files in "$@" +do + output=$(ls -R | grep $files) + if [[ $? -eq 0 ]] + then + echo $output | tr ' ' '\n' + else + echo the searched PATH is unexisting + fi +done diff --git a/ex03/ex03.sh b/ex03/ex03.sh new file mode 100755 index 0000000..8ad1525 --- /dev/null +++ b/ex03/ex03.sh @@ -0,0 +1,22 @@ +#!/bin/bash + + +if [[ -r $1 ]] +then + arguments=($2 $3 $4) + for arg in ${arguments[*]} + do + echo $arg $(grep -c $arg $1 ) + grep -n $arg $1 | cut -f1 -d":" + + done + exit 0 + else + exit 1 +fi + + + + + + diff --git a/ex04/ex04.sh b/ex04/ex04.sh new file mode 100755 index 0000000..c76caf4 --- /dev/null +++ b/ex04/ex04.sh @@ -0,0 +1,12 @@ +#!/bin/bash + path=$2 + pattern=$1 + if [[ -z $pattern || -z $path ]] + then + exit 1 + else + files=$(find $2) + basename $files + grep -n $pattern $files | cut -f1 -d":" + exit 0 + fi diff --git a/ex05/ex05.sh b/ex05/ex05.sh new file mode 100755 index 0000000..26157dd --- /dev/null +++ b/ex05/ex05.sh @@ -0,0 +1,45 @@ +#!/bin/bash + + +function sum(){ + evenresult=0 + oddresult=0 + for nums in $@ + do + if [[ $(($nums%2)) -eq 0 ]] + then + evenresult=$(($evenresult+$nums)) + else + oddresult=$(($oddresult+$nums)) + fi + done + result=$(($evenresult+$oddresult)) +} + + + + + +case $1 in + -e) + sum ${@:2} && echo $evenresult + exit 0 + ;; + -o) + sum ${@:2} && echo $oddresult + exit 0 + ;; + -s) + sum ${@:2} && echo $result + exit 0 + ;; + -m) + sum ${@:2} && echo $(( $result / $(($#-1)) )) + exit 0 +esac + echo "Error.." + exit 1 + + + + diff --git a/ex06/ex06.sh b/ex06/ex06.sh new file mode 100755 index 0000000..a41a4f2 --- /dev/null +++ b/ex06/ex06.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +function map(){ + +for args in ${@:2} + do + eval $1 $args +done + + +} + +map ${@} diff --git a/ex07/ex07.sh b/ex07/ex07.sh new file mode 100755 index 0000000..11f2417 --- /dev/null +++ b/ex07/ex07.sh @@ -0,0 +1,10 @@ +#!/bin/bash + + +if [[ -z $1 ]] +then + exit 1 +else + head -$1 resourses/surnames.txt | grep -v 'Q-Chem' | sed 's/-//;s/.$//' + exit 0 +fi diff --git a/ex08/ex08.sh b/ex08/ex08.sh new file mode 100755 index 0000000..24a001f --- /dev/null +++ b/ex08/ex08.sh @@ -0,0 +1,18 @@ +#!/bin/bash +nums=( zeroes, ones, twoes, threes, fours, fives, sixs, sevens, eights, nines) + + +if [[ $# -gt 1 || $# -lt 1 ]] +then + echo "Error.." + exit 1 +fi + + + +for i in {0..9} +do + arr[$i]=$(grep -o $i $1 | wc -l) + result+=' '${arr[$i]}' '${nums[$i]} +done +echo $result diff --git a/ex09/ex09.sh b/ex09/ex09.sh new file mode 100755 index 0000000..123145b --- /dev/null +++ b/ex09/ex09.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +case $1 in + -u) + grep "https://" $2 + ;; + -e) + grep '^[a-zA-Z0-9]\+@[a-zA-Z0-9]\+\.[a-z]\{2,\}' $2 + ;; + --url) + grep "https://" $2 + ;; + --email) + grep '^[a-zA-Z0-9]\+@[a-zA-Z0-9]\+\.[a-z]\{2,\}' $2 + ;; + +esac diff --git a/ex10/ex10.sh b/ex10/ex10.sh new file mode 100755 index 0000000..ef4d514 --- /dev/null +++ b/ex10/ex10.sh @@ -0,0 +1,10 @@ +#!/bin/bash + + + +if [[ -r $1 ]] +then +echo $(awk 'END{print NR}' $1) $1 +exit 0 +fi +exit 1