I am trying to write a script which will take my file and rename pt-1 to pt2for eg. testfile_pt-1_date.ts at the moment the script will correctly rename to file and copy it to the specified folder correctly.The problem I have is if there is a file eg. testfile_pt_date.ts, the file is not being renamed but is being copied which is not what I want, I want the file to be ignored, I am not sure why the for do loop is accepting a file with pt in it, anyone know where I have gone wrong.#! /bin/bashfile=$1for file in *_pt-1_*.tsdoecho $1    a=$(echo $1 | sed s/_pt-1_/_pt2_/)cp $1 $HOME/SGTV/${a##*/}echo $adone
Rename Files Bash Script - Loop Problem
bash;debian;rename
Instead of a loop, I would suggest you to use the dedicated rename tool. It's easier to read, faster to write and avoid confusion.rename 's/_pt-1_/_pt2_/' *_pt-1_*.tsWarning: rename is a mess on most distributions. If you're using Debian or a derivative, make sure the rename package is installed (not just the rename binary).