define image info in a bash variable

Started by twhite, October 25, 2017, 06:50:32 AM

Previous topic - Next topic

twhite

I use the following command to rename my images:


exiftool -m -r -progress -d "%Y-%m-%d_%H-%M-%S"  '-FileName<${DateTimeOriginal}.${SubSectimeOriginal}~~~${Exif:Model;tr/ /_/;s/EOS//;s/910G/910F/;s/PowerShot//;s/DIGITAL //;s/__+/_/g}--${LensID;s/ f\/.*$//;tr/ /_/}%+c.%le'  .

The result is: 2017-07-08_12-01-37.99~~~NIKON_D7200--Tamron_AF_16-300mm.nef

I would like to define the extra file information in a bash variable but it is not working:


extra_info="${Exif:Model;tr/ /_/;s/EOS//;s/910G/910F/;s/PowerShot//;s/DIGITAL //;s/__+/_/g}--${LensID;s/ f\/.*$//;tr/ /_/}"
exiftool -m -r -progress -d "%Y-%m-%d_%H-%M-%S"  '-FileName<${DateTimeOriginal}.${SubSectimeOriginal}~~~${extra_info}%+c.%le'  .


Any ideas?

Phil Harvey

Try this:


extra_info='${Exif:Model;tr/ /_/;s/EOS//;s/910G/910F/;s/PowerShot//;s/DIGITAL //;s/__+/_/g}--${LensID;s/ f\/.*$//;tr/ /_/}'
exiftool -m -r -progress -d "%Y-%m-%d_%H-%M-%S" '-FileName<${DateTimeOriginal}.${SubSectimeOriginal}~~~'"${extra_info}%+c.%le" .


You want to bash to expand ${extra_info}, so it should be in double quotes.  Bash doesn't interpolate within single quotes.

And you don't want bash to expand the ExifTool tag names, so they must be in single quotes.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

twhite