android scripting shell

Multiple file rename in Android

I’m trying to write a script using Android’s shell to rename all files of a given extension to add the .bak extension, and another to remove it.

This works for adding the .bak extension to all pdf files in the directory

for f in *.pdf
mv $f $f$ext

But bash string slicing using ${varname:index:length} doesn’t work in the android shell, so I’m at a loss as to how to remove the extension. Does anyone have any ideas?

EDIT: to clarify, I’m trying to find a way to delete the last four characters of a string in android shell. Other solutions that I have not considered which will solve my specific problem are also welcome.

Based on the given answer, the following code will remove a file extension from any file possessing that extension in a current directory in an unmodified Android shell (where .bak can be replaced with the extension of your choice)

for f in *.bak
mv $f ${f%.*}