LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash month variable (https://www.linuxquestions.org/questions/linux-newbie-8/bash-month-variable-263302/)

johniccp 12-06-2004 02:35 PM

bash month variable
 
I would like to execute some bash script ten months during the year, just not July or August. So, I tried to capture the month number and would compare latter, but it doesn't work.

For example:

#!/bin/sh
#
declare -i mon='date +%m'
echo $mon

Produces an error.
-bash: declare: date +%m: syntax error: operand expected (error token is "%m")

Oh, there must be a better way. Thanks in advance....

david_ross 12-06-2004 02:41 PM

Just use this (note the backticks):
mon=`date +%m`

If you are running from cron then you can also specify the months to run in field 4:
man crontab


All times are GMT -5. The time now is 10:10 PM.