Article 56D9M Batch process bash rename script

Batch process bash rename script

by
Johng
from LinuxQuestions.org on (#56D9M)
I am attempting to write a script to batch rename image files in a directory. ie change the image name from STA_1234.JPG to 1234-STA.jpg. The "STA" may be STB, STC, etc. The part that I'm having trouble with is "reading" the file names in sequence. The script so far looks like this:
Code:#!/bin/bash
echo

pwd

dirname "$(realpath $0)"

echo $dirname

for f in "$dirname"/*; do

read -a FILENAME #read -e FILENAME ###THE PART THAT DOES NOT WORK
FILENAMEX=$FILENAME

echo $FILENAMEX
filename=$FILENAMEX

#strip extension

JPGFile=${filename%.*}

echo "$JPGFile: "$JPGFile

#get file number

string=$JPGFile

echo "$string: "$string

number=${string:4}

echo "$number: "$number

#get panorama part

part=${string:0:-5} #part=${string:0:-5}

echo $part

#create new file name

rename="$number"-"$part".jpg""

echo $rename
echo

mv $FILENAMEX $rename

donelatest?d=yIl2AUoC8zA latest?i=RHpLrKlaU90:NcpBhcGz5fg:F7zBnMy latest?i=RHpLrKlaU90:NcpBhcGz5fg:V_sGLiP latest?d=qj6IDK7rITs latest?i=RHpLrKlaU90:NcpBhcGz5fg:gIN9vFwRHpLrKlaU90
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments