shell的典型应用--场景控制脚本

语法:
i=0 声明和初始化变量,=号两边不能有空格
declare -A array1 声明数组array1
${i} 引用变量i

for循环

for script_file in `ls -I "monitor.sh" ./ `
do
	echo -e '\033[40;35m' "The script:" ${i}  '==>'  ${script_file} '\033[0m'
	i=$((i+1))  ##这里的$符右边都是()不是花括号{}
done

该循环中的ls -I “monitor.sh” ./ 里面,-I 的i为大写,该命令表示显示当前目录下除了monitor.sh外的文件

在这里插入图片描述
执行结果
在这里插入图片描述

while循环

while true
do
	read -p "Please input a number [ ${numbers} ]":execshell
	if[[ ! ${execshell} =~ ^[0-9]+  ]];then
	exit 0
	/bin/sh ./${ssharray[$i]}
done

该循环中read -p 表示读取键盘输入的参数execshell,read指令还可以读取的超时时间
if语句中有两个[] ,是shell编程中if正则匹配的一个标准格式,内部[]是外部[]的一个条件

在这里插入图片描述

执行结果在这里插入图片描述

发布了91 篇原创文章 · 获赞 5 · 访问量 5439

猜你喜欢

转载自blog.csdn.net/weixin_43947156/article/details/104112833