grep --include glob with shell variable
Code:
grep -r $SEARCHDIR --include="day_$YYYY-$MM-*" -h -o -e PATTERN I use double quotes rather than single quotes because of the shell variables. I would have thought this would cause the shell to expand the "*" but this doesn't seem to be the case. Can anyone explain? |
Inside double quotes, the only special characters are dollar sign, the backticks, and the backslash.
The glob expansion is done at a different phase of the command parsing. It wouldn't make sense to expand it inside quotes, because one purpose of the quotes is to prevent spaces from splitting up the parameter. Since the expansion will almost always have spaces, an expansion within quotes would mean a list would get treated as a single parameter, whether or not the spaces were in a filename or separating two filenames. For example, suppose you had a directory with two files 'pic a.jpg' and 'pic b.jpg'. If the glob was expanded inside the quotes (which it isn't), then Code:
"*" Code:
"pic a.jpg pic b.jpg" |
All times are GMT -5. The time now is 03:09 AM. |