I'm trying to find out whether a file is an image or not and then do something according to the result.This works fine for file in the present working directory and in other directories:
file -ib "$i" | grep "image/"
But this only works with files in the present directory (where the script was called from)
TEST=$(file -ib "$i" | grep "image/")
if [ "$TEST" == "" ]
then
echo "Image"
else
echo "Not an image"
fi
So something like ../../my.jpg works in the first case, but always gives "Not an image" in the second case. I would like to use my script on files anywhere on the system.
Thanks for your help.
bash -x second-fragment.shshow as the value in$TEST? That'll tell you what you need to do to fix the problem.i=$1or similar in the script case?TESTlater? If not you can do the command directly in theif