I need to rename a part of a Java JAR file and I need to keep the version numbers in the filename:
Original file: hello-service-0.1.0.jar
Expected file: hello-my-service-0.1.0.jar
The following command does the job properly, but I need to be in the directory where the file sits, so I need to change-directory before run the rename command:
cd "$dir"
rename --verbose "s/hello-service/hello-my-service/" *.jar
cd -
But as I run the rename from a bash script, I would like to avoid the boilerplate code that change directory before and after the rename command.
I have something like this:
dir="/home/me/projects/hello/jar"
actual="hello-service"
expected="hello-my-service"
rename --verbose "s/$actual/$expected/" *.jar
How to specify the directory name for the rename command?