尝试编写一个android / linux脚本来列出特定目录中的文件作为菜单选项,然后使用该文件作为脚本中的变量执行一组命令...到目前为止,我已经得到了这个:
#!/system/bin/sh
l_count=0
cd /sdcard/themes
ls *.zip|while read l_file
do
l_count=`expr $l_count + 1`
echo "${l_count}. ${l_file}"
done
echo
echo "Pick a theme:"
read $choice
但是从那里我无法弄清楚如何将从l_count分配的号码分配给l_file
答案 0 :(得分:0)
想出来......答案是让脚本在do循环中写出第二个脚本。这是最后的剧本......
#!/system/bin/sh
l_count=0
cd /sdcard/themes
echo "#!/system/bin/sh" > /sdcard/themes/themer_tmp.sh
echo "echo 'Pick a theme:'" >> /sdcard/themes/themer_tmp.sh
echo "read choice" >> /sdcard/themes/themer_tmp.sh
echo case '$choice' in >> /sdcard/themes/themer_tmp.sh
ls *.zip|while read l_file
do
l_count=`expr $l_count + 1`
echo "${l_count}. ${l_file}"
echo "${l_count})" >> /sdcard/themes/themer_tmp.sh
echo echo '"boot-recovery" > /cache/recovery/command' >> /sdcard/themes/themer_tmp.sh
echo echo '"--update_package=/sdcard/themes/'${l_file}'"' '>> /cache/recovery/command' >> /sdcard/themes/themer_tmp.sh
echo echo '"--wipe_cache" >> /cache/recovery/command' >> /sdcard/themes/themer_tmp.sh
echo echo '"reboot"' '>> /cache/recovery/command' >> /sdcard/themes/themer_tmp.sh
echo "reboot recovery" >> /sdcard/themes/themer_tmp.sh
echo ";;" >> /sdcard/themes/themer_tmp.sh
done
echo "esac" >> /sdcard/themes/themer_tmp.sh
sh /sdcard/themes/themer_tmp.sh
希望这可以帮助其他人寻求类似的解决方案