I am having issues when trying to return the one image file that fits the parameters. $1 is the search parameter, in this incident it is real which is a tag on one of the images (not two) in the given folder. What happens when I call it ./test.sh real is it prints off both images, rather than just the one. I imagine it has to deal with me setting up the function return as a variable and/or my condition statement, but I am not quite sure.#!/bin/bashfor f in specim/*.jpgdo    image=$(exiftool -EXIF:XPKeywords $f | grep $1)    if [[ !  -z  $image// }  ]]; then    echo $ffiwhat's returned:../../test.sh realspecim/image2.jpgspecim/image.jpgThis bash script prints off what I want, only the one image rather than both (as the exiftool stuff which I don't want, but this was just a test):#!/bin/bashfor f in *.jpgdo    exiftool -EXIF:XPKeywords $f | grep $1doneresult:./test2.sh realXP Keywords                     : name;realany help would be appreciated and it's probably super simple...Thanks
Bash script condition always passing even when grep should return nothing
bash;scripting;grep;exif
It is probably as you suspected, just a minor change to fix, try instead:if [[ !  -z  $image  ]]; thenExplanationLet's say when there is a match by exiftool and grep, then your $image variable contains this:abcabcabcBut when there is no output, $image contains: (nothing)In your test condition, you had:if [[ !  -z  $image// }  ]]; thenSo, in the first case bash sees this:if [[ !  -z  abcabcabc// }  ]]; thenBut in the second case, bash sees this:if [[ !  -z  // }  ]]; thenThe test is saying if // } is NOT zero-value, then... however // } is always going to be not zero value, it is something, it is a string consisting of two slashes a space and a curly brace. So since there is something there, something not zero-value, that is why the then part is triggered even when you have no matches in $image. So by removing this // } it should work.