commit e82f22575f2705b34a3c5350edabe0fb5510a8e3 Author: 23_SemenovNS <23_SemenovNS@iux.local> Date: Tue Mar 31 17:51:18 2026 +0300 Добавить script3 diff --git a/script3 b/script3 new file mode 100644 index 0000000..b3d02f9 --- /dev/null +++ b/script3 @@ -0,0 +1,38 @@ +#!/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 \ No newline at end of file