I am trying to write a script which will take my file and rename pt-1 to pt2 for 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/bash
file=$1
for file in *_pt-1_*.ts
do
echo "$1"
a="$(echo $1 | sed s/_pt-1_/_pt2_/)"
cp "$1" "$HOME/SGTV/${a##*/}"
echo "$a"
done
file=$1
, but then$file
is overriden as you're doingfor file in ...
. And in the loop, you're not using$file
, but$1
instead.cp
and notmv
, and if your complaint is that it is copying the file, it's because you're explicitly telling it to.a="${file/_pt-1_/_pt2_}"