I need to write a shell script.
-for example
my files:
daily.gfr.gif, abc.gif , def.gif , fgr.gif , fgt.gif , current.abc.gif
I want to change as below:
1_daily.gfr.tlf , 2_abc.tlf , 3_def.tlf , 4_fgr.tlf , 5_fgt.tlf , 6_current.abc.tlf
I write a script:
for file in *.gif
do
filename=$(basename "$file")
filename=${filename%.*}
convert $file $filename.tlf
done
Is this right in your opinion? How can I add name changing?
*.gif; the names will be generated in alphabetic order. (2) Thebasenameoperation does nothing. You could have writtenfilename=$(basename "$file" .gif)to remove the suffix, or you can do what you do on the next line. (3) You need a counter and an increment operation:counter=1outside the loop,${counter}_$filename.tlfas the second argument toconvert, and((counter++))or similar to increment the counter.