Bash – How to rename multiple files by replacing word in file name geting from the shell script variables

bashscripting

This question like this thread.
How to rename multiple files by replacing word in file name?

My example is more complex than the above topic.
The two variables are $name and $ newname getting from the shell script other location.
$name and $ newname may have the unicode words or special symbles like []<>♫…etc,so could anyone help me to provide a method to add a part of script in shell scrit to solve file name replacing question.

BTW,I try to type two kind of commands to change the part of file name, but it can't work.

rename.ul '$name' '$newname' /home/fy6877/test/final/* 
ls /home/fy6877/test/final/|xargs -I$ rename.ul '$name' '$newname' $ 

Best Answer

Use rename or mmv. Neither of them should care whether there are UTF-8-encoded unicode symbols in your names, or whether the arguments given on the command line are variables or plain literals. Make sure to pass arguments as "$name" not '$name' to ensure that the value of the variable gets passed to the rename command.

Related Topic