I'm trying to use this line in a bash script to update my cron jobs:
(sudo crontab -l ; echo "0 6 1-7 * * [ $(/usr/bin/date +\%u) == 7 ] && sh $script_path > $log_path") | sort - | uniq - | sudo crontab -
Prior to this, $script_path
and $log_path
have been defined. I know this works in general. I just have one hang up. $(/usr/bin/date +\%u)
resolves to an empty string when the crontab file is written to. I need that literal text to remain in place.
(Not that is really matters, but the point of that is to verify the day of the week. This job is to be run on the first Saturday of the month).
How do I "escape" that whole substring?
You may escape each problematic character with \
(see Hunter.S.Thompson's answer) or just use single quotes, the enclosed string being written as is:
(sudo crontab -l ; echo '0 6 1-7 * * [ $(/usr/bin/date +\%u) == 7 ] && sh '"$script_path > $log_path") | sort -u | sudo crontab -
I personally tend to avoid escaping characters, as I think it harms readability.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments