This works as expected, returning the filename passed as the second argument from the shell if the keywords property contains a value of animals, as per the exiftool documentation.
However, I just cannot find a way to use a variable instead of hardcoding the value. I first tried just using the variable name:
This is more of a Linux question about the shell you are using rather than an exiftool one. So my knowledge is limited.
But I believe you have to have double quotes around your first variable and it has to be outside of the single quotes. I think it would be something like this exiftool -if '$iptc:keywords =~ /'"$1"'/i' -filename "$2"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
exiftool version: 13.25 (Linux, Debian 13)
I am trying to use a variable to set a value in a shell script in the
ifoption.This works as expected, returning the filename passed as the second argument from the shell if the
keywordsproperty contains a value ofanimals, as per the exiftool documentation.However, I just cannot find a way to use a variable instead of hardcoding the value. I first tried just using the variable name:
but this fails. I expect that this would be because the variable $1 is not being expanded.
I tried using double quotes, which I would expect would be expanded in my shell, bash:
exiftool -if "$iptc:keywords =~ /$1/i" -filename "$2"This fails.
How can I use a variable in an
if?Last edit: Angel_Blue01 2026-08-17
This is more of a Linux question about the shell you are using rather than an exiftool one. So my knowledge is limited.
But I believe you have to have double quotes around your first variable and it has to be outside of the single quotes. I think it would be something like this
exiftool -if '$iptc:keywords =~ /'"$1"'/i' -filename "$2"That works, thank you!