I’m trying to create a for loop that goes through a directory, and renames each file in that directory.
dir2=$1
for i in $dir2
do
file=$(basename "$i")
b=${file%.*}
c=${file#"$stub"}
d=-BACKUP
e=$b$d$c
mv "$i" "$e"
I’m trying to change each file:i to become $e.
For example, if I have a directory, and there is one file in it called test.txt, the file would be changed to test-BACKUP.txt
I’m having problems in that it’s not changing the files withing the directories, it’s changing the directory itself.
1 Answer