语法:
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正则匹配的一个标准格式,内部[]是外部[]的一个条件
执行结果