I am running into an issue in a script I have. I have the following:
~/test> echo bar > foo.txt; echo bar > foo.c
~/test> flags="--include \"*.txt\""
~/test> echo $flags
--include "*.txt"
~/test> grep -rHI $flags bar .
~/test> grep -rHI --include "*.txt" bar .
./foo.txt:bar
So, basically grep -rHI $flags bar .
is not evaluating to the same as grep -rHI --include "*.txt" bar .
There is a way around this (using eval), but I would be interested in understanding why $flags is being treated differently than its literal expansion in this case.
Apparently, this is being marked as duplicate. The quoted question deals with whitespace between elements, whereas, this question is about precedence of expansion as choroba pointed out. (The two seem to have the same solution though). I had found several references to using eval/array, but I didn't find a satisfactory answer as to what was the cause of the problem, and hence I was asking.