Files
2026-03-31 17:51:18 +03:00

38 lines
920 B
Bash
Raw Permalink 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/bash
error() {
[[ $1 =~ ^-?[0-9]+$ ]]
}
echo "Введите первое число:"
read num1
if ! error "$num1"; then
echo "Ошибка: '$num1' не является целым числом"
exit 1
fi
echo "Введите второе число:"
read num2
if ! error "$num2"; then
echo "Ошибка: '$num2' не является целым числом"
exit 1
fi
# НОД
if [ -f "./script1.sh" ] && [ -x "./script1.sh" ]; then
nod_result=$(./script1.sh $num1 $num2 2>/dev/null | grep -o '[0-9]*$')
echo "НОД: $nod_result"
else
echo "Ошибка: скрипт script1.sh не найден"
exit 1
fi
# НОК
if [ -f "./script2.sh" ] && [ -x "./script2.sh" ]; then
nok_result=$(./script2.sh $num1 $num2 2>/dev/null | grep -o '[0-9]*$')
echo "НОК: $nok_result"
else
echo "Ошибка: скрипт script2.sh не найден"
exit 1
fi