I am trying to write a script using the Android shell to rename all files of a given extension, to add the .bak extension, and the other is to delete it.
This works to add the .bak extension to all PDF files in the directory
ext=.bak for f in *.pdf do mv $f $f$ext done
But bash string slicing using ${varname:index:length} does not work in the Android shell, so I donβt understand how to remove the extension. Does anyone have any ideas?
EDIT: to clarify, I'm trying to find a way to remove the last four characters of a string in an android shell. Other solutions that I have not considered that will solve my specific problem are also welcome.
UPDATE: Based on this answer, the following code will remove the file extension from any file that has this extension in the current directory in the unmodified Android shell (where .bak can be replaced with the extension of your choice)
for f in *.bak do mv $f ${f%.*} done
source share