Search code examples
bashshellexiftool

Exiftool command in Bash for-loop not working


I'm trying to write and overwrite jpg metadata with exiftool in a bash for-loop, but a specific command won't work in the loop. I want to overwrite the gpstimestamp with the datetimeoriginal data, this works if executed on the commandline, but not in the script..

for f in $(ls *.jpg); do

    [... stuff that works]

    exiftool "-gpstimestamp<datetimeoriginal" $f
done

Any ideas why this isn't working in the loop?


Solution

  • The for loop can be done in a simpler way:

    #!/bin/bash
    for f in *.jpg
    do
    
        [... stuff that works]
    
        exiftool "-gpstimestamp<datetimeoriginal" $f
    done
    

    Note: You instead of running a for loop, you can execute exiftool to process all *.jpg files in the directory using:

    exiftool info

    exiftool "-gpstimestamp<datetimeoriginal" -ext jpg .
    

    exiftool man

    -ext EXT (-extension) Process files with specified extension