An unquoted variable is empty or contains spaces
Common[ $X = prod ] becomes [ = prod ] when X is empty, and [ a b = prod ] when X is "a b".
Confirm
bash -x script.sh 2>&1 | grep '\['
The [ command as it actually ran, with missing or extra words
Fix
- Quote every variable in [ ]: [ "$X" = "prod" ], [ -f "$F" ].
- In bash scripts, [[ $X == prod ]] avoids the splitting entirely.
if [ -f "$F" ]; then …
Reproduced on bash 5.2.21: the quoted test found my file.txt.