Computing.Net > Forums > Unix > Assign to a Variable

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Assign to a Variable

Reply to Message Icon

Name: Nish
Date: December 30, 2002 at 00:06:59 Pacific
OS: Solaris
CPU/Ram: 256
Comment:

I need to calculate the Yesterday's date and received a good code from Unix forum.
I need to assign the yesterdays Date (MONTH and DATE eg. 1229 for Dec 29)to a Variable ,say myvar.
$myvar can be used in any where of the program after that !

#!/bin/ksh
GetDate ()
{
set -A DAYS Sat Sun Mon Tue Wed Thu Fri Sat
set -A MONTHS Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
YESTERDAY=$((`date +%d` -1))
MONTH=`date +%m`
YEAR=`date +%Y`
NDAY=`date +%u`
WEEKDAY=${DAYS[`date +%u`]}
if [ $YESTERDAY -eq "0" ]
then
MONTH=$((MONTH-1))
if [ $MONTH -eq "0" ]
then
MONTH=12
YEAR=$((YEAR-1))
fi

set `cal $MONTH $YEAR`
shift $(($# - 1))
YESTERDAY=$1
fi
TMONTH=${MONTHS[MONTH]}
$YEAR
echo $MONTH$YESTERDAY
return 0
}

GetDate

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Appreciate your Help regarding the same.

Cheers,
Nish.



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: December 30, 2002 at 04:47:57 Pacific
Reply:

Is there a reason that adding the line

myvar=$MONTH$YESTERDAY

before the return statement of your function does not work for you?


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Assign to a Variable

Prob Assign Row count to a variable www.computing.net/answers/unix/prob-assign-row-count-to-a-variable/7875.html

assigning a variable to a script www.computing.net/answers/unix/assigning-a-variable-to-a-script/5566.html

Assign Date to a Var www.computing.net/answers/unix/assign-date-to-a-var/3915.html