I've got a problem i'm facing for 6-7 hours and i can't overcome it , that's why i'm asking for your help.I need to create a bash script that accesses a folder and renames all the files from it with a new name followed by a number that represents alalphabetic hierachy and a new extension.
The parameters are in this order:
(The new name , the new extension , and the folder where i'm searching).
As an example : ./rename.sh work .txt Documents
Let's say that initially the document (Documents) contained :
Therefore , afer running the script the document will containt the following: work01.txt(from a.txt)
The problem is that somehow i'm duplicating the files and i'm creating a big mess. Here is the script (rename.sh):
#!/bin/bash if [ -z "$3" ] then echo "No argumets supplied" else mic="0" i="1" max="9" for file in `ls $3 | sort -V`; do if ( test $i -le 9) then cp $3/$file $3/$1$mic$i.$2 rm -r $3/$file else if ( test $i -ge 9 ) then cp $3/$file $3/$1$i.$2 rm -r $3/$file fi fi i=$((i+1)) done echo "$max" fi