[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: storing current month in shell variable..



On 9:33 Dec 16, 2004 "Mulley, Nikhil" <mnikhil corp untd com> wrote:
> Hi ,
> Nikhil again ... :)
> I wanna store the current month in a shell variable , for which I am
> attempting to do like this ... #!/usr/bin/sh
> MON=`(date | awk '{print $2}')
> echo $MON
> But when I execute the script , I get nothing...
> Can anyone point me in where I have gone wrong ??

The awk stuff is not needed. You can get the month (either numerical or
string) directly from the date command.


# Prints 01-12
monthnum=$(date +%m)
echo $monthnum

# Prints Jan-Dec
monthshort=$(date +%b)
echo $monthshort

# Prints January-December
monthlong=$(date +%B)
echo $monthlong


--Tony


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]