I am trying to set a PREFIX variable in a bash command line, say
echo $PREFIX
CA_RA
Yet when trying to rename a file, it gives
Tag 'PREFIX' not defined ,
as in the command
exiftool '-testname<$PREFIX-%.4nC.%e' .
This way would be easier to update bunch of files, not to change the PREFIX on the command.
Thanks!
The shell does not interpolate within single quotes. Use double quotes instead if you want to use shell variables.
- Phil
exiftool "-testname<$PREFIX-%.4nC.%e" .
Warning: Invalid tag name 'l-nl_cl-%.4nc.%e'
still, seems not to be working...
This is Common Mistake #5c (https://exiftool.org/mistakes.html#M5). You are not copying any tags, you are setting TestName a static value. Try this
exiftool "-testname=$PREFIX-%.4nC.%e" .
(I should have caught this)
Is there a way to combine two, eg.
(These do not work, only examples)
exiftool "-testname=$PREFIX-<${Megapixels}%.4nC.%e" .
exiftool "-testname=$PREFIX" '-testname<${Megapixels}%.4nC.%e' .
to give outcome:
'./CA_RA-0.110-0001.jpeg'
If this cannot be done in one go, I would run it twice. The second run to skip x-length charters at the beginning of a picture file, if that would be easier.
But perhaps a way to achieve it in one run..
Thanks!
There are a number of ways to do this. With bash, escaping "$" in the non-shell variable should work like this:
exiftool "-testname<$PREFIX-\${Megapixels}%.4nC.%e" .
You could also change from double to single quotes:
exiftool "-testname<$PREFIX"'-${Megapixels}%.4nC.%e' .
- Phil
Thanks guys, indeed both ways work!