Author Topic: Help with -if syntax  (Read 599 times)


  • Newbie
  • *
  • Posts: 4
Help with -if syntax
« on: May 09, 2019, 11:49:52 AM »

I am trying to use exiftool to identify Pentax Pixel Shift images, but I have not been able to make it work.

I started by running:
exiftool -PixelShiftResolution -Quality -csv *.pef
, to make sure that I have files to process, but ran into trouble when I got to the -if logic.  I have tried all below, without success.  Can someone tell me what I am doing wrong?  Thanks!

exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution == 1" *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution == On" *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution eq On" *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution eq 1" *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution = 1" -csv *.pef
exiftool -PixelShiftResolution -Quality -if "$PixelShiftResolution = On" -csv *.pef
exiftool -Name -if $PixelShiftResolution="On" -csv *
exiftool -Name -if $PixelShiftResolution="On" -csv .
exiftool -Name -if '$PixelShiftResolution = 1' -csv *
exiftool -Name -if '$PixelShiftResolution == 1' -csv *
exiftool -Name -if '$PixelShiftResolution' -csv *
exiftool -Name -if '$PixelShiftResolution eq "On"' -csv *
exiftool -Name -if '$PixelShiftResolution = "On"' -csv *
exiftool -Name -if '$PixelShiftResolution == "On"' -csv *
exiftool -Name -if '$PixelShiftResolution == 1' -csv *
exiftool -Name -if '$PixelShiftResolution = 1' -csv *
exiftool -Name -if '$PixelShiftResolution eq 1' -csv *
exiftool -Name -if '$Quality ge 7' -csv *
exiftool -Name -if "$Quality ge 7" -csv *
exiftool -Name -if "$Quality = 7" -csv *
eexiftool -PixelShiftResolution -Quality -if "$Quality eq 7" -csv *

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 17944
    • ExifTool Home Page
Re: Help with -if syntax
« Reply #1 on: May 09, 2019, 12:00:15 PM »
Wow, that's a lot of hit-n-miss.

Try this (the quoting assumes you are on Mac or Linux):

exiftool -PixelShiftResolution -Quality -if '$PixelShiftResolution eq "On"' -ext pef .

The 'eq' operator is used for string comparisons, and "On" must be quoted because it is a string.

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


  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 4854
Re: Help with -if syntax
« Reply #2 on: May 09, 2019, 12:11:18 PM »
Since I'm slow and had already typed all this out, here's some more details.

The PixelShiftResolution has a raw numeric value of 0 or 1, which exiftool will display (printConv) as a string of Off/On.  To do a string comparison, you would use eq to see if it is exactly equal (no substring search).  Also, as a string, what you are comparing to must be in quotes.  Case does matter in this comparison.  The type of quotes depends upon the system.  Phil shows the Mac/Linux version.  On Windows CMD, you need double quotes around the whole things and single quotes around the matching string (Powershell is different and I'm not sure exactly how to quote it there, possibly the same as Mac/Linux).  This should work under Windows:
-if "$PixelShiftResolution eq 'On' "

You can also compare the raw value.  In that case, you would add a hashtag to the end of the name, use the double equal sign ==, and wouldn't need to quote the value.
-if "$PixelShiftResolution# == 1"

Finally, you can use a regex match.  This allows for substring searches as well as case insensitive search option by adding a trailing i.
-if "$PixelShiftResolution =~/on/i"
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.


  • Newbie
  • *
  • Posts: 4
Re: Help with -if syntax
« Reply #3 on: May 10, 2019, 07:08:53 AM »
Thanks Phil.  I tried everything BUT putting doubles inside singles (Windows ).  This worked:

exiftool -Name -if "$PixelShiftResolution eq 'On'" .

Thanks again!