Exact same EXIFTOOL command works from command line but from within a script

Started by iSilentP, February 22, 2025, 02:35:24 PM

Previous topic - Next topic

iSilentP

I am using EXIFTOOL on a Mac. I am trying to write a Mac shell script to remove keywords from a jpg file.

I am trying to auto-generate, via shell script, the following command:

exiftool -overwrite_original -keywords-='Bokeh-Blur(inPixio)_20240325_120516' 1.jpg

The script does in fact produce the command line exactly as it is shown above, but fails to remove the keyword from the 1.jpg file when ran from a script vs command line manual entry.

When I copy and paste the contents of the script (verbatim as it would have resulted from the script) inside a terminal window it works.

Please have a look at these images that try to describe what I am experiencing.

1. https://www.smugmug.com/gallery/n-rWtznc/i-69tdM23/A

The first screen capture shows a terminal session where I have copied into clipboard the contents of the script and pasted them into a new terminal window and upon execution the image file I am trying to modify does not get changed. (red and green sections).

Also in this screen capture (in the yellow section), I copied and pasted (verbatim) the output/resulting line from the script that should make the change to the file. ('Command Line in the script' from inside the red section and this worked.

2. https://www.smugmug.com/gallery/n-rWtznc/i-mvFhMTb/A

I later found about the '-v' EXIFTOOL parameter and modified and ran the script. The output of that command shows that apparently, some attributes were updated (Rewritten), but the end result was same '1 image files unchanged'.

Not sure how to proceed with this. Any help would be appreciated.

I have also included the 1.jpg file I am trying to modify. In this case, trying to remove the 'Bokeh-Blur(inPixio)_20240325_120516' keyword.

Bottom line is that the EXIFTOOL command works if manually entered at the command line, but does not from a script file.  I would like to automate this via the use of scripts, because this is just a shell for further expansion, but am stuck trying to figure out why the inconsistency between running through a script vs entering the exact same command manually from the command line.

The file can be downloaded from here:
https://drive.google.com/drive/folders/1TPpYR-Rd6auAOD4LQ_2uAdkchTMeEuQz?usp=sharing

Thanks for looking into this.

~ Tony

greybeard

#!/bin/sh
echo
echo pwd: `pwd`
echo

ls -al 1.jpg

filespec="1.jpg"

echo
echo List of keywords: `exiftool -keywords "$filespec"`
echo

key1="Bokeh-Blur(inPixio)_20240325_120516"

echo exiftool -overwrite_original -keywords-="'$key1'" $filespec
exiftool -overwrite_original -keywords-=$key1 $filespec

echo
echo List of keywords: `exiftool -keywords "$filespec"`
echo

StarGeek

Quote from: greybeard on February 22, 2025, 03:41:53 PMexiftool -overwrite_original -keywords-=$key1 $filespec

So it was passing the single quotes as part of the command, i.e. it evaluated to
-keywords-="'Bokeh-Blur(inPixio)_20240325_120516'" 1.jpg
instead of
-keywords-='Bokeh-Blur(inPixio)_20240325_120516' 1.jpg
?

Also of note, Greybeard shows that you can directly ask for Keywords instead of using grep. Using grep might suppress any warnings, errors, or other useful information.
"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