Skip to content
6 changes: 6 additions & 0 deletions ex01/hello_world.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
if ! [ -z $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

6 changes: 6 additions & 0 deletions ex02/ex02.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
str=$( echo $1 | tr " " "\n" )
for i in $str
do
ls -R | grep -Fi $i || echo "the searched PATH is unexisting"
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

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

if [ -z $1 ]; then
exit 1
fi

if ! [ -z $1 ]; then
touch .f
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
fi
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 file creation

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

if [ -z $1 ] || [ -z $2 ]; then
exit 1
fi

echo $2 | cut -d'/' -f 2
grep -in $1 $2 | cut -d : -f 1
Copy link
Owner

Choose a reason for hiding this comment

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

No args and Without first arg tests are failed

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

if [ -z $2 ]; then
echo "0"
exit 0
fi

summ=0

for i in $@
do
if [ "$1" == "-s" ]; then
summ=$(echo "$summ + $i" | bc)
elif [ "$1" == "-m" ]; then
summ=$(echo "$summ + $i" | bc)
elif [ "$1" == "-e" ]; then
[ $((i%2)) -eq 0 ] && summ=$(echo "$summ + $i" | bc)
elif [ "$1" == "-o" ]; then
[ $((i%2)) -ne 0 ] && summ=$(echo "$summ + $i" | bc)
else
echo "Error.."
exit 1
fi
done

if [ "$1" == "-m" ]; then
shift 1
summ=$(echo $(( "$summ / $#" )))
fi

echo "$summ"
Copy link
Owner

Choose a reason for hiding this comment

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

Two flags input test are failed, also please rewrite it with switch statement

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

if [ $1 ]; then
map $@
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

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

if [ -z "$1" ] || [ "$1" -eq 0 ]; then
exit 1
fi

answer=$(head "-$1" resourses/surnames.txt | grep -v 'Q-Chem' | sed "s/\.//g ; s/\-//g" | cat )

if [[ $answer ]]; then
echo "$answer"
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.

approved

4 changes: 2 additions & 2 deletions ex07/test_ex07.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
}

@test "Test on 0 lines returns error" {
run ex07.sh 0
run bash ex07.sh 0

[ "$status" -eq 1 ]
}

@test "Test on 2 lines return empty string" {
run ex07.sh 2
run bash ex07.sh 2

[ "$status" -eq 0 ]
[ "$output" = $'' ]
Expand Down
21 changes: 21 additions & 0 deletions ex08/ex08.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

if [ -z $1 ] || [ $# -gt 1 ] ; then
echo "Too many(few) arguments"
exit 1
fi

if [ ! -f "$1" ]; then
echo "Error.."
exit 1
fi

answer=""
words=( zeroes ones twoes threes fours fives sixs sevens eights nines )
wlen=${#words[@]}
for (( i=0; i<${wlen}; i++ ))
do
answer+=$(grep -o "$i" $1 | wc -l)
answer+=" ${words[$i]}, "
done
echo "$answer" | sed 's/..$//'
Copy link
Owner

Choose a reason for hiding this comment

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

approved

7 changes: 2 additions & 5 deletions ex08/test_ex08.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ "$status" -eq 0 ]
[ "$output" = "10 zeroes, 13 ones, 4 twoes, 7 threes, 3 fours, 3 fives, 0 sixs, 0 sevens, 0 eights, 1 nines" ]

}

@test "Too many arguments" {
run bash ex08.sh resources/digitfile.txt digit.txt
Expand All @@ -15,16 +15,13 @@
}

@test "Too few arguments" {
run bash ex08.sh

run bash ex08.sh
[ "$status" -eq 1 ]
[ "$output" = "Too many(few) arguments" ]
}

@test "File doesn't exist" {
run bash ex08.sh resources/digitfile

[ "$status" -eq 1 ]
[ "$output" = "Error.." ]
}

13 changes: 13 additions & 0 deletions ex09/ex09.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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

16 changes: 8 additions & 8 deletions ex09/test_ex09.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,59 @@

@test "Find emails in file without emails" {
run bash ex09.sh -e resources/email1.txt

[ "$status" -eq 1 ]
[ "$output" = "" ]
}

@test "Find emails in file with emails" {
run bash ex09.sh -e resources/email2.txt

[ "$status" -eq 0 ]
[ "$output" = "craig@bbhost.us" ]
}

@test "Find urls in file without urls" {
run bash ex09.sh -u resources/url1.txt

[ "$status" -eq 1 ]
[ "$output" = "" ]
}

@test "Find urls in file with urls" {
run bash ex09.sh -u resources/url2.txt

[ "$status" -eq 0 ]
[ "$output" = "https://en.emailfake.com/usjima1129.ga/craig
https://mail.google.com/mail/u/0/" ]
}

@test "Find emails in file with emails and urls" {
run bash ex09.sh -e resources/emailurl.txt

[ "$status" -eq 0 ]
[ "$output" = "craig@bbhost.us" ]
}

@test "Find urls in file with emails and urls" {
run bash ex09.sh -u resources/emailurl.txt

[ "$status" -eq 0 ]
[ "$output" = "https://en.emailfake.com/usjima1129.ga/craig
https://mail.google.com/mail/u/0/" ]
}

@test "Test long flag for email" {
run bash ex09.sh --email resources/emailurl.txt

[ "$status" -eq 0 ]
[ "$output" = "craig@bbhost.us" ]
}


@test "Test long flag for url" {
run bash ex09.sh --url resources/emailurl.txt

[ "$status" -eq 0 ]
[ "$output" = "https://en.emailfake.com/usjima1129.ga/craig
https://mail.google.com/mail/u/0/" ]
Expand Down
10 changes: 10 additions & 0 deletions ex10/ex10.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if [ ! -f "$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