当脚本启动时,它会从目录中的文件中列出一个菜单并提示选择,当选择一个文件时,会显示另一个菜单,其中包含用户想要执行的操作,现在用户想要使用选项 6 返回上一个菜单,该操作已成功完成,但当用户从主菜单中选择另一个选项时,脚本似乎没有更新:
#!/bin/bash
echo "Welcome to Led_Config"
echo "============================"
echo "Please select a led to configure"
echo "---------------------------------"
print_menu(){
i=({0..7})
for file in /sys/class/leds/*
do
echo ${i[i++]}".""$(basename "$file")"
done
echo ${i[7]}".""Quit"
echo "------------------------------------"
printf "Please enter a number (1-8) for the led to configure or quit:"
read ans
clear
}
print_menu
while [ $ans != '' ]
do
if [[ $ans = 5 ]]
then
echo "LED0"
echo "====="
PS3="Please enter a number (1-6) for your choice:"
options=("turn on" "turn off" "associate with a system event" \
"associate with the performance of a process" \
"stop association with a process performance" \
"quit to main menu")
select opt in "${options[@]}"
do
case $REPLY in
1) echo 1 | sudo tee /sys/class/leds/led0/brightness;;
2) echo 0 | sudo tee /sys/class/leds/led0/brightness;;
3) echo "Associate Led with a System Event";
echo "============================";
echo "Available Events are:";
echo "---------------------";
i=({0..34})
for file in /sys/class/leds/led0/*
do
echo ${i[i++]}".""$(basename "$file")"
done;;
6) print_menu;
esac
done
elif [[ $ans = 6 ]]
then
echo "LED1"
echo "===="
PS3="Please enter a number (1-6) for your choice:"
options=("turn on" "turn off" "associate with a system event" \
"associate with the performance of a process" \
"stop association with a process performance" \
"quit to main menu")
select opt in "${options[@]}"
do
case $REPLY in
1) echo 1 | sudo tee /sys/class/leds/led1/brightness;; 2) echo 0 | sudo tee /sys/class/leds/led1/brightness;;
6) print_menu;;
esac
done
fi
if [[ $ans = 7 ]]
then
exit
else
echo "under construction"
break
fi
done