[mythtv-users] Script quoting problem

Ian Campbell ijc at hellion.org.uk
Sun Apr 8 07:40:47 UTC 2018


On Sat, 2018-04-07 at 20:45 +0200, Klaus Becker wrote:
> My script (script.sh) is:
> 
> ----------------

In general you should start all shell scripts with "set -e" to cause
errors to lead to an exit. Using "set -x" in addition can help you see
what is going on.

> # Cut everything after the point
> oldname=$(ls *.ts | cut -d. -f1)
> newname=$(ls *.mpg | cut -d. -f1)

These will be all the basenames in one variable, not just one at a
time. That seems unlikely to be what you want. Also the individual
names will not be quoted, so you would have no way of separating them.
Using echo to examine these variables will demonstrate this.

> # Rename file
> for file in *.ts; do
> 	mv $file $(echo $file | sed 's/$oldname/$newname/g')
> Done

Neither $oldname nor $newname is in the required regex format (you
would need | between the individidual names), but since you've used
single quotes they won't be substituted anyhow, sed will by trying to
substitute the literal strings "$oldname" and "$newname"...

It seems like what you want to do is to "collapse" the symlinks, that
is to promote the target of the symlink into the place of the symlink
itself. The shell command "readlink" will give you the target of the
symlink which you give to it, so try:

   #!/bin/bash

   set -ex

   for file in *.mpg; do
       target=$(readlink "$file")
       echo mv -iv "$target" "$file"
   done

Run it and if you are happy with what it proposes to do remove the
safety echo.

I would reiterate Mark's comment though -- doing this will make things
unplayable in mythtv and leave stale entries in your myth recording
lists which you will need to cleanup separately.

Ian.



More information about the mythtv-users mailing list