storing current month in shell variable..

Anthony E. Greene tony at greene-family.org
Thu Dec 16 18:29:31 UTC 2004


On 9:33 Dec 16, 2004 "Mulley, Nikhil" <mnikhil at 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




More information about the redhat-list mailing list