android - How to read a file extension from a variable in Bash? -
i working on major update android utility flash in recovery , uses bash scripting... problem is, kinda know nothing bash!
right now, have 2 files... common file contains variables , script file holds file lists.
here problem part of common script:
if [ ${android_version} == 5.* ]; rm -rf /system/$file_name; else if [ -e ${file_name}.* ]; rm -rf /system/$file_name; else rm -f /system/$file_name.apk; fi; fi; and here's example of $file_name's come from:
# aosp aosp_remove_list="bootanimation browser ..."; bootanimation_list="media/bootanimation.zip"; browser_list="app/browser app/chromebookmarkssyncadapter"; so in common file, looks see if lollipop. if not, (this issue) supposed @ file name individual app lists , see if contains file extension. if doesn't remove $file_name + .apk.
so in above example, browser's files .apk added , removed system bootanimation .zip doesn't removed.
you should maybe use suffix truncation perform this.
with ${your_var_name%.zip} you'll ride of after .zip including zip, if present of course.
you can try in terminal:
a="toto.zip" echo ${a%.zip} #= > toto you'll more details possibilities here: http://www.tldp.org/ldp/abs/html/parameter-substitution.html