Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ex01/hello_world.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/bash

if [ "$1" ]
then
echo "Hello, $1!"
else
echo "Hello, World!"
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

17 changes: 17 additions & 0 deletions ex02/ex02.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
ls_out=$(ls -R | xargs -n1)
echo "$ls_out" > .assist
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do it without assist file creation, solution of this ex is more easy than your, one cycle and only one var

found=false

params=$(awk -F " " '{print $1" " $2}' <(echo $1))
for var in $params
do
grepped=$(grep "$var" .assist)
if [[ $grepped ]]; then
echo "$grepped"
found=true
fi
done
if [ "$found" = false ]; then
echo "the searched PATH is unexisting"
fi
13 changes: 13 additions & 0 deletions ex03/ex03.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
if [ -z $1 ]; then
exit 1
fi
touch .f
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same, do it without file creation

for i in "${@:2}"
do
grep -in $i $1 > .f
n=$(cat .f | wc -l)
echo "$i $n"
awk -F: '{print $1}' .f
done
rm .f
9 changes: 9 additions & 0 deletions ex04/ex04.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/bash
if [ -z $1 ] || [ -z $2 ]; then
exit 1
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again please do it without file creation

echo "$2" | rev | cut -d"/" -f1 | rev
grep -in $1 $2 > .f
n=$(cat .f | wc -l)
awk -F: '{print $1}' .f

54 changes: 54 additions & 0 deletions ex05/ex05.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
keys=( -s -e -o -m )
for k in ${keys[*]}
do
key_found=false
if [ "$1" = "$k" ]; then
key_found=true
break
fi
done
if [ $key_found = false ]; then
echo Error..
exit 1
fi
if [ -z $2 ]; then
:
elif ! [ "$2" -eq "$2" >& /dev/null ]; then
echo "Error.."
exit 1
fi
cmd=$0
op=$1
shift
res=0
case $op in
"-s")
for i in $@
do
res=$(echo "$res + $i" | bc)
done
;;
"-e")
for i in $@
do
[ $((i%2)) -eq 0 ] && res=$(echo "$res + $i" | bc)
done
;;
"-o")
for i in $@
do
! [ $((i%2)) -eq 0 ] && res=$(echo "$res + $i" | bc)
done
;;
"-m")
for i in $@
do
res=$(echo "$res + $i" | bc)
done
res=$(echo $(( $res / $# )))
;;
*)
;;
esac
echo "$res"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

10 changes: 10 additions & 0 deletions ex06/ex06.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
map(){
com=$1
shift
for i in "$@"
do
eval "$com $i"
done
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

10 changes: 10 additions & 0 deletions ex07/ex07.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
if [[ -z "$1" ]] || [[ "$1" -eq 0 ]]; then
exit 1
fi
res=$(head "-$1" resourses/surnames.txt | grep -v 'Q-Chem' | sed "s/\.//g ; s/\-//g" | cat)
if [[ $res ]]; then
echo "$res"
else
echo ""
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test on 0 lines returns error and Test on 2 lines return empty string tests are failed

15 changes: 15 additions & 0 deletions ex08/ex08.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

zer=$(grep -o "0" resources/digitfile.txt | wc -l)" zeroes"
ones=$(grep -o "1" resources/digitfile.txt | wc -l)" ones"
twos=$(grep -o "2" resources/digitfile.txt | wc -l)" twos"
th=$(grep -o "3" resources/digitfile.txt | wc -l)" threes"
ft=$(grep -o "4" resources/digitfile.txt | wc -l)" fours"
fif=$(grep -o "5" resources/digitfile.txt | wc -l)" fives"
six=$(grep -o "6" resources/digitfile.txt | wc -l)" sixs"
sev=$(grep -o "7" resources/digitfile.txt | wc -l)" sevens"
nin=$(grep -o "8" resources/digitfile.txt | wc -l)" eights"
ten=$(grep -o "9" resources/digitfile.txt | wc -l)" nines"

echo $zer, $ones, $twos, $th, $ft, $fif, $six, $sev, $nin, $ten

Copy link
Owner

@vpetrusenko vpetrusenko Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11 changes: 11 additions & 0 deletions ex09/ex09.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
if [ -z $1 ] || [ -z $2 ]; then
exit 1
fi
if [ $1 = '-u' ] || [ $1 = '--url' ]; then
grep -Po '(^|\t)https:[A-Za-z0-9\/\.]+' $2
elif [ $1 = '-e' ] || [ $1 = '--email' ]; then
grep -Po '(^|\t)[A-Za-z0-9\.]+@[A-Za-z0-9\.]+\.[A-Za-z0-9\.]+' $2
else
exit 1
fi
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

8 changes: 8 additions & 0 deletions ex10/ex10.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
if [ -d $1 ]; then
exit 1
fi
for i in $@
do
echo "$(awk 'END{print NR}' $i) $i"
done
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved