Why grep fails
Doing this in a terminal:
Fails - Waiting for input
$ grep "index123"
Works - Receives input from STDIN
$ echo -e "line1\nline2\nindex123blah\n" | grep "index123"
index123blah
The 2nd one works because we presented input for grep to parse via STDIN. grep will take input from either STDIN or a file. In your scenario:
if [[ "$d"=="*.out" && grep "index123"]]; then exit 1; fi
It's not parsing either, hence it's failing.
Your issue
From the looks of your code I believe you want something like this. To start here's some sample data:
$ mkdir -p 1/2/{3..5}
$ echo "index123" > 1/2/3/blah.out
$ echo "index123" > 1/2/3/blip.out
$ echo "index" > 1/2/blip.out
$ echo "index" > 1/2/blah.out
And a modified form of your script:
$ cat loopy.bash
#!/bin/bash
while IFS= read -r d; do
grep -l "index123" "$d" && exit 1
done < <(find . -type f -name "*.out")
Running:
$ ./loopy.bash
./1/2/3/blah.out
Emits the first file it found that has index123 string, and exits.
While loop a good solution?
I wouldn't do it this way. Using a while loop here in this manner isn't necessary. It would be better to use a find .... | xargs ... architecture, or find ... -exec type of solution.
See @DopeGhoti's answer for a better approach to using find with either -exec or xargs.
Printing containing directory
If you simply want to print the containing directory tree where the matching file resides, you can use dirname to do this like so:
$ cat loopy2.bash
#!/bin/bash
while IFS= read -r d; do
grep -q "index123" "$d" && dirname "$d" && exit 1
done < <(find . -type f -name "*.out")
And running it:
$ ./loopy2.bash
./1/2/3