set value using string with spaces

Started by kaikin, May 31, 2019, 07:42:50 PM

Previous topic - Next topic

kaikin

I've just discovered exiftool and think it is a great resource!

I'm just having trouble using exiftool in a shell script using a string variable which contains spaces and can't find the right combination of quotes to make this work:

theCaption="my caption"
exiftool -description=$theCaption IMG_1506.jpg



which gives the following error:
Error: File not found - caption
    1 image files updated
    1 files weren't updated due to errors


I can successfully do
exiftool -description="my caption" IMG_1506.jpg

and have tried embedding single or double quotes within the string variable, or using $'theCaption' in the first example, but always get the same error. Does someone have an example of how to do this?

I'm running this on Mac OS Sierra
Many thanks.

Phil Harvey

This should do it:

exiftool -description="$theCaption" IMG_1506.jpg

Shell variables are interpolated inside double quotes.  But not single quotes, which is why '$thecaption' won't work.

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