I've created a bash script to automate editing the EXIF data in image files. I can't figure out how to get the script to issue a command with the * wildcard (asterisk) to specify a file name pattern.
The script properly assembles a CLI command that executes properly if I enter it manually outside of the bash script. But from within bash, the script returns a file not found error.
Here's my code:
#!/bin/bash
# Usage: Place this script in the directory of jpg files whose EXIF data is to be edited.
echo Press enter to accept default values.
# Enter camera manufacturer.
default="Pentax"
read -p "Enter camera manufacturer [$default]: " cameramake
cameramake=${cameramake:-$default}
exifargs="-model=$cameramake"
# Enter camera model.
default="K1000"
read -p "Enter camera model [$default]: " cameramodel
cameramodel=${cameramodel:-$default}
exifargs="$exifargs -make=$cameramodel"
# Enter slide film type.
default="Kodachrome slide film."
read -p "Enter slide film type [$default]: " filmtype
filmtype=${filmtype:-$default}
exifargs="$exifargs -imagedescription='PIE PS-5000 slide scanner. VueScanner 32 scanning softare. $filmtype'"
# Enter file name pattern.
default="*.jpg"
read -p "Enter file name pattern [$default]: " namepattern
namepattern=${namepattern:-$default}
exifargs="$exifargs $default"
#Use exiftool to edit EXIF data
echo /home/richard/Dropbox/Pictures/Tools/ExifTool/exiftool "$exifargs"
/home/richard/Dropbox/Pictures/Tools/ExifTool/exiftool "$exifargs"
I inserted the "echo" command to check that my command is correct. It is (at leats for the CLI). The results of running the script is:
richard@richard-laptop:~/Dropbox/Pictures/Photos/test$ sh exifbatch.sh
Press enter to accept default values.
Enter camera manufacturer [Pentax]:
Enter camera model [K1000]:
Enter slide film type [Kodachrome slide film.]:
Enter file name pattern [*.jpg]:
/home/richard/Dropbox/Pictures/Tools/ExifTool/exiftool -model=Pentax -make=K1000 -imagedescription='PIE PS-5000 slide scanner. VueScanner 32 scanning softare. Kodachrome slide film.' *.jpg
No file specified
But when I enter the exact same text as create by the script on the command line, it functions as I want, finding the files in the current directory that match the name pattern. (The warnings thrown by exiftool are expected.):
richard@richard-laptop:~/Dropbox/Pictures/Photos/test$ /home/richard/Dropbox/Pictures/Tools/ExifTool/exiftool -model=Pentax -make=K1000 -imagedescription='PIE PS-5000 slide scanner. VueScanner 32 scanning softare. Kodachrome slide film.' *.jpg
Warning: [minor] Ignored empty rdf:Seq list for darktable:mask_id - 1987_California-01.jpg
Warning: [minor] Ignored empty rdf:Seq list for darktable:mask_id - 1987_California-02.jpg
2 image files updated
How do I change my basch script so that the command will executed as it does on the CLI? I think there's something wrong with how I'm using the * character. If I don't put quotation marks (") around the $exifargs variable name, bash immediately interprets the *.jpg and appends all the file names into the string, which then confounds the exiftool command.
Thanks!