Resta 7 días de la fecha de hoy.

Resta 7 días de la fecha de hoy.

Aquí está mi guión. Necesito restar 7 días de la fecha de hoy y usarlo en un nombre de archivo. Estoy usando una Mac.

#/bin/bash
DATE=$(date -d "-7 days")
echo $DATE

Cuando ejecuto este script .sh, aparece esto:

$ /Users/xxxxxxx/xxxxxxxx/dateTest.sh 
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

Respuesta1

Con BSD datenecesitas una sintaxis diferente:

DATE="$(date -v-7d)"

En mi FreeBSD man dateincluye:

 -v      Adjust (i.e., take the current date and display the result of the  
         adjustment; not actually set the date) the second, minute, hour,  
         month day, week day, month or year according to val.  If val is  
         preceded with a plus or minus sign, the date is adjusted forwards  
         or backwards according to the remaining string, otherwise the  
         relevant part of the date is set.  

información relacionada