[mythtv-users] Script quoting problem

Klaus Becker colonius at free.fr
Sat Apr 7 18:58:29 UTC 2018


Le samedi 7 avril 2018, 20:45:04 CEST Klaus Becker a écrit :
> Hi,
> 
> I want to rename the files in "show_names", created by mythlink.pl.
> 
> I have in a test directory:
> 
> $ ls
> 1234.ts  5678.ts  film1.mpg  film2.mpg
> 
> I wish to rename 1234.ts in film1.ts and 5678.ts in film2.ts.
> 
> I have a quoting problem with my script.
> 
> My script (script.sh) is:
> 
> ----------------
> # Cut everything after the point
> oldname=$(ls *.ts | cut -d. -f1)
> newname=$(ls *.mpg | cut -d. -f1)
> 
> # Rename file
> for file in *.ts; do
> 	mv $file $(echo $file | sed 's/$oldname/$newname/g')
> Done
> ----------------
> 
> $ bash script.sh
> mv: '1234.ts' et '1234.ts' are the same file
> mv: '5678.ts' et '5678.ts' are the same file
> 
> However "echo $oldname" shows "1234 5678" (that's what I want), and "echo
> $newname" shows "film1 film2".
> 
> I searched on the web and i tried other quoting manners I found there, but I
> can't get it work as I want.
> 
> I am beginner in scripting and I can't find the error.
> 
> It's just a simplified example script. Once it works, it should be easy to
> make it work for MythTV recordings.
> 
> Bye
> 
> Klaus


I made a mistake:

I want to give the files in my recording directory the names in "show_names". 
But my above question still is the same.

Klaus




More information about the mythtv-users mailing list