Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, I'm new in writing unix scripts. Currently I need to write a script to calculate previous date. Lucky this web site has infomation on it. I have found the following problem from this web site which will work great for me. One thing though, I'm currently working on Linux and it doesn't have ksh installed. It only has csh, bash, and bsh. What do I need to do in order for me to convert this ksh program to bash program? Your help will be appreciated. Thank you.
#!/bin/ksh
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 DecYESTERDAY=$((`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))
fiset `cal $MONTH $YEAR`
shift $(($# - 1))
YESTERDAY=$1
fiTMONTH=${MONTHS[MONTH]}
# uncomment next line for debugging
# echo $WEEKDAY $YESTERDAY $MONTH $TMONTH $YEAR
echo $YESTERDAYPete

If you would like to install ksh on your linux box, look for the package pdksh.
Try running this script under bash. They have a lot of similarities. It may work.

Hi:
On my Red Hat 7.1 system:
1) obviously, change #!/bin/ksh to #!/bin/bash
2) Remove the -A option from the two set commands. bash doesn't support the -A.
Other than that, it worked.
Regards,
Nails

The above sript worked great for me,Thanks for all your help. I have one more question though regarding to the above script. What does the line "shift $(($# - 1))" do in the script. I know, "shift" will shift whatever in the set one to the left but what about "$#" means? I try to find the reference on my unix books but couldn't find anything that mention this kind of expression or similar. Can someone tell me what this means? Thanks.

![]() |
![]() |
![]() |

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