Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

expr - date issue

Status
Not open for further replies.

christiniaroelin

Programmer
Sep 15, 2004
26
US
Hi,
Im facing the following issue while running the below script:
output from the script : 0 6
required output : 06

#! /bin/ksh
export stamp=${stamp- "$(printf $(expr `date '+%m'` - 1 ))"}
echo $stamp

if [ $month -lt 10 ]
then
export stamp=0$stamp
fi

print $stamp

Please advice on the above.
Thanks!!
christinia
 
Code:
#!/bin/ksh

typeset -Z2 STAMP
export STAMP=${STAMP-$(expr `date '+%m'` - 1)}
print $STAMP
This will output "[tt]06[/tt]".

Hope this helps.
 
What happens in January? Is "[tt]00[/tt]" an acceptable value?

If not, change it to...
Code:
#!/bin/ksh

typeset -Z2 STAMP
export STAMP=${STAMP-$(expr `date '+%m'` - 1)}
(( ! STAMP )) && STAMP=12

print $STAMP
Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top