Добавить script3
This commit is contained in:
38
script3
Normal file
38
script3
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user