How to check if a value matches

Started by Geoff_12889, July 26, 2023, 04:04:14 PM

Previous topic - Next topic

Geoff_12889

How would I go about checking if a value matches?

My use case is I want to check if "-Make" == "FUJIFILM".

My little understanding would be something like:

-exiftool [path] -Make == FUJIFILM

Phil Harvey

Try this:

exiftool -filename -if "$make =~ /FUJIFILM/i" FILE

The comparison above will match "FUJIFILM" anywhere in the Make value, ignoring case.  And print the file name if it matches.

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

Geoff_12889

Quote from: Phil Harvey on July 26, 2023, 04:07:02 PMTry this:

exiftool -filename -if "$make =~ /FUJIFILM/i" FILE

The comparison above will match "FUJIFILM" anywhere in the Make value, ignoring case.  And print the file name if it matches.

- Phil

I tried that option and get the following:

Error: File not found - FILE
You were meant to enter any valid file name, not "FILE" literally.
    1 files failed condition
    0 image files read
    1 files could not be read

I tried removing "FILE" from the end and get this result:

1 files failed condition
But it should match.

Geoff_12889

I'm on Mac so I needed to use single quotes. It seems to be working.

How would I have it return 'true' instead of the file name?

Phil Harvey

Yes.  My signature tells about the quoting.  I assume Windows unless told otherwise.

The exit status will be 0 on success, or 2 if the file failed the condition.

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