#!/bin/bash
# 测试下载应用
path="/home/zhang/program/bash/scripts"
# 判断path是否存在
[ ! -d "${path}" ] && {
echo "directory is not exists"
exit 1
}
# 打印提示信息
cat <<END
1.[install redis]
2.[install mongo]
3.exit
Please enter the number
END
# 从stdin获取输入
read num
# 根据expr特性判断输入的是否是数字
expr ${num} + 1 &>/dev/null
[ $? -ne 0 ] && {
echo "please enter the number"
exit 2
}
[[ ${num} =~ [1-3] ]] && {
[ ${num} -eq "1" ] && {
[ -f ${path}/redis.sh -a -x ${path}/redis.sh ] || {
echo "The file does not exist or no execution rights"
exit 4
}
echo "start installing redis..."
sleep 2
. ${path}/redis.sh
exit $?
}
[ ${num} -eq "2" ] && {
[ -f ${path}/mongo.sh -a -x ${path}/mongo.sh ] || {
echo "The file does not exist or no execution rights"
exit 4
}
echo "start installing mongo..."
sleep 2
. ${path}/mongo.sh
exit $?
}
[ ${num} -eq "3" ] && {
echo "bye"
exit $?
}
} || {
echo "Only input is allowed 1、2 or 3"
exit 3
}
shell之选择下载
最新推荐文章于 2024-07-17 20:41:49 发布