Files
lab/unix/25-1/5/main.sh
2025-12-19 11:40:54 +03:00

63 lines
926 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/env bash
set -exu
if [ "$#" -ne 1 ]; then
echo "Неверное число аргументов" >&2
exit 1
fi
COUNT=0
N=$1
int_handler() {
case $COUNT in
0)
echo "Доброе утро"
;;
1)
echo "Добрый день"
;;
2)
echo "Добрый вечер"
;;
esac
COUNT=$(((COUNT + 1) % 3))
return 0
}
chdir() {
mkdir -p "C"
if [ ! -d "C" ]; then
echo "Не удалось создать каталог ${PWD}/C" >&2
return 1
fi
cd "C" || {
echo "Не удалось перейти в каталог ${PWD}/C" >&2
return 1
}
return 0
}
quit_handler() {
for ((i=0; i<$N; i++)) do
chdir
if [ "$?" -ne 0 ]; then
echo "Обработка сигнала QUIT не удалась"
return 1
fi
done
exit 1
}
trap int_handler INT
trap quit_handler QUIT
while true; do
read -t 1 || true
done