Linux shell environment variable

Started by aniecki, October 21, 2020, 03:13:49 AM

Previous topic - Next topic

aniecki

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!


Phil Harvey

The shell does not interpolate within single quotes.  Use double quotes instead if you want to use shell variables.

- 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 ($).

aniecki

#2
exiftool "-testname<$PREFIX-%.4nC.%e"  .

Warning: Invalid tag name 'l-nl_cl-%.4nc.%e'

still, seems not to be working...

StarGeek

This is Common Mistake #5c.  You are not copying any tags, you are setting TestName a static value.  Try this
exiftool "-testname=$PREFIX-%.4nC.%e"  .
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

...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 ($).

aniecki

#5
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!

Phil Harvey

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
...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 ($).

aniecki