I have a script that repeats the same (very long)
grep command many times. I want to make the script more readable by cutting the line length, so I tried to put parts of the command into variables.
This is the line (that repeats many times in the script, with different parameters):
rsync -av --delete -R --exclude=alternatives /etc/ /backup.raw/ | grep -E '^deleting|[^/]$' >> /var/log/rsync.log
That line works ok. What I did trying to abbreviate it, is:
_rscmd='rsync -av --delete -R' _mn=/backup.raw/ _grep='grep -E "^deleting|[^/]$"' _rslog=/var/log/rsync.log
so the "final" line could be:
$_rscmd --exclude=alternatives /etc/ $_mn | $_grep >> $_rslog
But that line fails on the
$_grep variable. How can I write it right? I tried to use
'…', with no luck. Pay attention to the original grep command that works, please.