Skip to content

Commit 764963d

Browse files
committed
Done module-bash
1 parent 3cc4032 commit 764963d

File tree

10 files changed

+155
-0
lines changed

10 files changed

+155
-0
lines changed

ex01/hello_world.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/bash
2+
3+
if [ "$1" ]
4+
then
5+
echo "Hello, $1!"
6+
else
7+
echo "Hello, World!"
8+
fi

ex02/ex02.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
ls_out=$(ls -R | xargs -n1)
3+
echo "$ls_out" > .assist
4+
found=false
5+
6+
params=$(awk -F " " '{print $1" " $2}' <(echo $1))
7+
for var in $params
8+
do
9+
grepped=$(grep "$var" .assist)
10+
if [[ $grepped ]]; then
11+
echo "$grepped"
12+
found=true
13+
fi
14+
done
15+
if [ "$found" = false ]; then
16+
echo "the searched PATH is unexisting"
17+
fi

ex03/ex03.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
if [ -z $1 ]; then
3+
exit 1
4+
fi
5+
touch .f
6+
for i in "${@:2}"
7+
do
8+
grep -in $i $1 > .f
9+
n=$(cat .f | wc -l)
10+
echo "$i $n"
11+
awk -F: '{print $1}' .f
12+
done
13+
rm .f

ex04/ex04.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/bash
2+
if [ -z $1 ] || [ -z $2 ]; then
3+
exit 1
4+
fi
5+
echo "$2" | rev | cut -d"/" -f1 | rev
6+
grep -in $1 $2 > .f
7+
n=$(cat .f | wc -l)
8+
awk -F: '{print $1}' .f
9+

ex05/ex05.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
keys=( -s -e -o -m )
3+
for k in ${keys[*]}
4+
do
5+
key_found=false
6+
if [ "$1" = "$k" ]; then
7+
key_found=true
8+
break
9+
fi
10+
done
11+
if [ $key_found = false ]; then
12+
echo Error..
13+
exit 1
14+
fi
15+
if [ -z $2 ]; then
16+
:
17+
elif ! [ "$2" -eq "$2" >& /dev/null ]; then
18+
echo "Error.."
19+
exit 1
20+
fi
21+
cmd=$0
22+
op=$1
23+
shift
24+
res=0
25+
case $op in
26+
"-s")
27+
for i in $@
28+
do
29+
res=$(echo "$res + $i" | bc)
30+
done
31+
;;
32+
"-e")
33+
for i in $@
34+
do
35+
[ $((i%2)) -eq 0 ] && res=$(echo "$res + $i" | bc)
36+
done
37+
;;
38+
"-o")
39+
for i in $@
40+
do
41+
! [ $((i%2)) -eq 0 ] && res=$(echo "$res + $i" | bc)
42+
done
43+
;;
44+
"-m")
45+
for i in $@
46+
do
47+
res=$(echo "$res + $i" | bc)
48+
done
49+
res=$(echo $(( $res / $# )))
50+
;;
51+
*)
52+
;;
53+
esac
54+
echo "$res"

ex06/ex06.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
map(){
3+
com=$1
4+
shift
5+
for i in "$@"
6+
do
7+
eval "$com $i"
8+
done
9+
}
10+

ex07/ex07.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
if [[ -z "$1" ]] || [[ "$1" -eq 0 ]]; then
3+
exit 1
4+
fi
5+
res=$(head "-$1" resourses/surnames.txt | grep -v 'Q-Chem' | sed "s/\.//g ; s/\-//g" | cat)
6+
if [[ $res ]]; then
7+
echo "$res"
8+
else
9+
echo ""
10+
fi

ex08/ex08.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
zer=$(grep -o "0" resources/digitfile.txt | wc -l)" zeroes"
4+
ones=$(grep -o "1" resources/digitfile.txt | wc -l)" ones"
5+
twos=$(grep -o "2" resources/digitfile.txt | wc -l)" twos"
6+
th=$(grep -o "3" resources/digitfile.txt | wc -l)" threes"
7+
ft=$(grep -o "4" resources/digitfile.txt | wc -l)" fours"
8+
fif=$(grep -o "5" resources/digitfile.txt | wc -l)" fives"
9+
six=$(grep -o "6" resources/digitfile.txt | wc -l)" sixs"
10+
sev=$(grep -o "7" resources/digitfile.txt | wc -l)" sevens"
11+
nin=$(grep -o "8" resources/digitfile.txt | wc -l)" eights"
12+
ten=$(grep -o "9" resources/digitfile.txt | wc -l)" nines"
13+
14+
echo $zer, $ones, $twos, $th, $ft, $fif, $six, $sev, $nin, $ten
15+

ex09/ex09.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
if [ -z $1 ] || [ -z $2 ]; then
3+
exit 1
4+
fi
5+
if [ $1 = '-u' ] || [ $1 = '--url' ]; then
6+
grep -Po '(^|\t)https:[A-Za-z0-9\/\.]+' $2
7+
elif [ $1 = '-e' ] || [ $1 = '--email' ]; then
8+
grep -Po '(^|\t)[A-Za-z0-9\.]+@[A-Za-z0-9\.]+\.[A-Za-z0-9\.]+' $2
9+
else
10+
exit 1
11+
fi

ex10/ex10.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
if [ -d $1 ]; then
3+
exit 1
4+
fi
5+
for i in $@
6+
do
7+
echo "$(awk 'END{print NR}' $i) $i"
8+
done

0 commit comments

Comments
 (0)