Skip to content

TASKS

Develop a script that takes a string as an argument and returns its reverse version, changing uppercase letters to lowercase and back

./loops1.sh "Hello World"

DLROw OLLEh

./loops1.sh "bash"

HSAB

./loops1.sh "EPAM"

mape

#!/bin/bash
# Put your code here
str="$1"
res=""
for((i=0; i < ${#str}; i++)); do
char="${str:i:1}"
if [[ $char =~ [A-Z] ]]; then
res="${char,,}"$res
elif [[ $char =~ [a-z] ]]; then
res="${char^^}"$res
else
res="$char"$res
fi
done
echo $res

An unsorted list is passed to the script. Write a program that will output the sum of even numbers

./cond1.sh "1,2,3,4,5,6,7"

12

./cond1.sh "4,3,1"

4

./cond1.sh "2,2,9,3,8"

12

./cond1.sh ""

0

#!/bin/bash
IFS=',' read -r -a arr <<< "$1"
arr_size=${#arr[@]}
if [[ arr_size == 0 ]]; then
echo 0
exit 0
fi
sum=0
for((i=0; i < arr_size; i++)); do
if (( arr[i] % 2 == 0 )); then
sum=$(( arr[i] + sum ))
fi
done
echo $sum

Develop a script that takes the temperature value in Celsius OR Kelvins and returns the inverse value. The formula is pretty simple: C = K - 273; K = C + 273

./temp.sh 55C

328K

./temp.sh 122K

  • 151C

./temp.sh 98C

371K

#!/bin/bash
str="$1"
if [[ ${str: -1} == "C" ]]; then
echo "$(( ${str:0:-1} + 273 ))K"
else
echo "$(( ${str:0:-1} - 273 ))C"
fi

Develop script that takes any string and calculate count of letters, numbers, symbols *!@#$%^&()_+ inside except whitespaces

./check_string.sh "Hello ! ** 564gfhf"

Numbers: 3 Symbols: 3 Letters: 9

./check_string.sh "Hello ! +"

Numbers: 0 Symbols: 2 Letters: 5

./check_string.sh "Hello !!"

Numbers: 0 Symbols: 2 Letters: 5

#!/bin/bash
# Place your code here
nums=0
chars=0
sym=0
str2="$1"
for (( i=0; i < ${#str2}; i++ )); do
ch="${str2:i:1}"
if [[ $ch =~ [A-Za-z] ]]; then
(( chars++ ))
elif [[ $ch =~ [\*!\@\#\$%\^\&()_+] ]]; then
(( sym++ ))
elif [[ $ch =~ [0-9] ]]; then
(( nums++ ))
else
continue;
fi
done
echo "Numbers: $nums Symbols: $sym Letters: $chars"

Develop a pow() function that takes two arguments (a, b) and raises the first argument to the power of the second (a^b).

pow 2 3 8

pow 2 5 32

#!/bin/bash
function pow() {
x=$1
y=$2
echo $(( x ** y ))
}
echo $(pow 2 3) # 8

Develop the shortest() function, which can take an unlimited number of arguments(strings) and output the shortest argument.

shortest "This" "is" "Bash" "Functions" "Task" is

If there are more than two arguments, output each string on a new line. In an order they are passed to function.

shortest "Java" "Bash" "Python" Java Bash

Terminal window
function shortest() {
# Step 1: find minimum length
min_len=${#1}
for i in "$@"; do
if (( ${#i} < min_len )); then
min_len=${#i}
fi
done
# Step 2: print all strings with min length
for i in "$@"; do
if (( ${#i} == min_len )); then
echo "$i"
fi
done
}
echo $(shortest "Java" "Bash" "Python") # Java Bash

Develop a print_log() function that takes a string as an argument and outputs the same string with the date at the beginning. In order for the automatic check to work, the string must be in this format: YEAR-MONTH-DAY HOUR:MINUTES

print_log "Hello World!" [2022-05-10 13:04] Hello World!

print_log "Hello Bash!" [2022-05-10 13:10] Hello Bash!

Terminal window
function print_log() {
echo "["$(date +"%Y-%m-%d %H:%M")"] $1"
}
echo $(print_log "Hello Bash!") # [2022-05-10 13:10] Hello Bash!

Develop a script that takes number (count of needed folders up to 26) as an argument and create this folders in current directory with next naming convention folder_<[a-z]>.

./array.sh 5

5 folders created: folder_a, folder_b, folder_c, folder_c, folder_d

./array.sh 1

1 folder created: folder_a

./array.sh 2

2 folders created: folder_a, folder_b

#!/bin/bash
num=$1
for (( i = 0; i < $num; i++ )); do
char=$(printf "\\$(printf '%03o' "$((97+i))")")
mkdir "folder_$char"
done

Write a Bash script that reads a log file named sys_logs.log line by line.

For each line:

  • If both of the following fields exist:
    • endpoint
    • ResponseTime

Then print a simplified output containing only these two fields in the format:

Endpoint=<endpoint_value> ResponseTime=<response_time_value>ms
[2026-03-06T10:01:02Z] endpoint=/api/v1/users ResponseTime=120ms Code=200 IP=192.168.1.10
[2026-03-06T10:01:05Z] endpoint=/api/v1/orders Code=201 IP=192.168.1.11
[2026-03-06T10:01:08Z] endpoint=/api/v1/products ResponseTime=95ms Code=200 IP=192.168.1.12
[2026-03-06T10:01:11Z] ResponseTime=310ms Code=200 IP=192.168.1.20
#!/bin/bash
while read line
do
if [[ $line =~ **endpoint=([^[:space:]]+)** ]]; then
endpoint="${BASH_REMATCH[1]}"
else
continue
fi
if [[ $line =~ **ResponseTime=([0-9]+)ms** ]]; then
time="${BASH_REMATCH[1]}"
else
continue
fi
echo "Endpoint=$endpoint ResponseTime=${time}ms"
done < **sys_logs.log**