Here's an example :
VALID_MODELINE_FMT=$'\'"[0-9]+x[0-9]+@[0-9]+" ([0-9]+)(\.[0-9]+)?( [0-9]+){8} [+|-]hsync [+|-]vsync\''
REJECTED_MODELINES=$(printf "$MODELINES_STR" | grep -vE $VALID_MODELINE_FMT)
When running the command, I get errors that do not make any sense:
grep: ([0-9]+)(\.[0-9]+)?(: No such file or directory
grep: [0-9]+){8}: No such file or directory
grep: [+|-]hsync: No such file or directory
grep: [+|-]vsync": No such file or directory
When substituting the variable everything works:
REJECTED_MODELINES=$(printf "$MODELINES_STR" | grep -vE '"[0-9]+x[0-9]+@[0-9]+" ([0-9]+)(\.[0-9]+)?( [0-9]+){8} [+|-]hsync [+|-]vsync'
Basically, all I want to do is simply centralize the regex format string inside one variable because it's used at a few places. Seems I just can't, probably because of poor substitution design inherent to shell programming. However, I wonder if I can circumvent this, ideally without meddling with single quotes.
Thanks! :)
grepcommand. However do check yourVALID_MODELINE_FMTby echoing it to make sure if that is what you want.$'\'of the regexp. The first regexp character is", which does not have a particular meaning inside the regexp. There is no need for escaping it.