if input file name is
xyz.txt output for the today's run should be xyz_Feb.txt.
i tried this code
1 curmth=`date +%m`
2 mth=(Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
3 prevmth=${mth[$((curmth - 1))]}
4 echo $prevmth
but its giving a syntax error at Line 2 : `(' unexpected.
TIA.
Regards,
naren
$ date '+%b'
Mar
$ date -d 'last month' '+%b'
Feb
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
hi when i ran the above code i am getting the following error
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
If you have the GNU version of date:
date -d 'last month' +%b
Or try the date arithmetic section of the FAQ:
<http://cfaj.freeshell.org/shell/cus-faq.html#6>
Also, Chapter 8 of my book, which is online at
<http://cfaj.freeshell.org/shell/ssr/08-The-Dating-Game.shtml>
> if input file name is
> xyz.txt output for the today's run should be xyz_Feb.txt.
>
> i tried this code
> 1 curmth=`date +%m`
> 2 mth=(Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
> 3 prevmth=${mth[$((curmth - 1))]}
> 4 echo $prevmth
>
> but its giving a syntax error at Line 2 : `(' unexpected.
The shell you are using doesn't have arrays (they are not
standard).
curmth=`date +%b`
mth=DecNovOctSepAugJulJunMayAprMarFebJanDec
tmp=${mth#*$curmth}
prevmth=${tmp%${tmp#???}}
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
set 'Dec' 'Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct'
'Nov'
set x `expr \`date '+%m'\` + 1` ${1+"$@"}; shift
eval "prevmth=\${$1}"
IFS=';'
set -f
set -- $(locale abmon)
set x "${12}" "$@"
now=$(date +%m)
shift "${now#0}"
lastmonth=$1
--
St�phane