SH Script to Rename .apk.odex files I have written a script to utilize dexopt-wrapper to odex a folder of .apk's

#!/bin/sh

SYSAPP=/mnt/extSdCard/FilesToOdex/system/app/
SYSPRIVAPP=/mnt/extSdCard/FilesToOdex/system/priv-app/

for i1 in $SYSAPP*.apk ; do
        echo "Odexing $i1..."
        dexopt-wrapper $i1 $i1.odex
done

for i2 in $SYSPRIVAPP*.apk ; do
        echo "Odexing $i2..."
        dexopt-wrapper $i2 $i2.odex
done


for file1 in $SYSAPP*.apk.odex; do
    mv "$file1" "`basename $file1 .apk.odex`$file1.odex"
done
for file2 in $SYSPRIVAPP*.apk.odex; do
    mv "$file2" "`basename $file2 .apk.odex`$file2.odex"
done


The odexing part works, but as you can see it creates a bunch of .apk.odex files

So my question is:


How can I setup the odexing portion to not write the files out as *.apk.odex?
OR, How can I get the mv to properly rename the *.apk.odex files to be just *.odex files?


I tried:

for file1 in $SYSAPP*.apk.odex; do
    mv "${file1}" "${file1%.odex}" 
done
for file2 in $SYSPRIVAPP*.apk.odex; do
    mv "${file2}" "${file2%.odex}"
done


but it turned all my .apk.odex files to .apk
That's rather a shell scripting question to be asked at Super User. Your answer can be found here: Extract filename and extension in bash:

for file1 in $SYSAPP*.apk.odex; do
    mv "${file1}" "${file1%.*}.odex" 
done
for file2 in $SYSPRIVAPP*.apk.odex; do
    mv "${file2}" "${file2%.*}.odex"
done


should work on most shells, supposedly.

Update:

You can even omit half of your script by adapting this to your original statements: dexopt-wrapper $i1 ${i1%.*}.odex should create the file with the correct naming, so no need to rename it later. To make your script real short and handy:

#!/bin/sh
SYSAPP=/mnt/extSdCard/FilesToOdex/system/app/
SYSPRIVAPP=/mnt/extSdCard/FilesToOdex/system/priv-app/

for i1 in $SYSAPP*.apk $SYSPRIVAPP*.apk; do
    echo "Odexing $i1..."
    dexopt-wrapper $i1 ${i1%.*}.odex
done


That's all you should need :)