输入2会执行对应的脚本2

执行对应的脚本,输入0会分析日志,输入2会执行对应的脚本2

输入非数字 f 则退出

用if判断中断循环

可以加入判断,只允许输入ID,数字等,先用ctrl+c中断。

输入什么,然后就会输出什么。

输入2,然后会输出2

中断循环


输出numbers

关联数组赋值

关联数组
ssharray[$i]=${script_file}


.sh
#!/bin/bash
#重置显示文字的颜色为系统默认的颜色
reset=$(tput sgr0)
# 声明关系数组
declare -A sh_array
# 统计文件的数量
i=0
numbers=""
workFile_path="/root/work/"
for script_file in $(ls -I 'monitor_main.sh' /root/work)
do
echo -e '\e[1;31m' "The Script:" ${i} '==>' ${reset} ${script_file}
grep -E "^\#Program function" ${workFile_path}${script_file}
sh_array[$i]=${script_file}
numbers="${numbers} | ${i}"
# echo ${sh_array[$i]}
i=$((i+1))
done
#echo ${numbers}
while true
do
read -p "Please input a number [ ${numbers} ]:" input_num
echo ${input_num}
if [[ ! ${input_num} =~ ^[0-9]+ ]];then
exit 0
fi
/bin/bash /root/work/${sh_array[$input_num]}
done
#!/bin/bash
resettem=$(tput sgr0)
declare -A ssharray
i=0
numbers=""
for script_file in `ls -I "monitor_man.sh" ./`
do
echo -e '\e[1;35m'"The Script:" ${i} '===>' ${resettem} ${script_file}
grep -E "^\#Program function" ${script_file}
ssharray[$i]=${script_file}
# echo ${ssharray[$i]}
numbers="${numbers} | ${i}"
i=$((i+1))
done
while true
do
read -P "input number [ ${numbers} ]" execshell
if [[ ! ${execshell} =~ ^[0-9]+ ]];then
exit 0 #判断输入内容如果不是数字则退出
fi
/bin/sh ./${ssharray[$execshell]}
done