1

尝试编写一个 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

4

1 回答 1

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

希望这可以帮助其他寻求类似解决方案的人

于 2012-12-13T16:09:49.783 回答