The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Necesito la fecha de creacion, modificacion y ultimo acceso de un fichero! palitodlselva Shell Programming and Scripting 1 10-09-2009 02:08 AM
Dada Mail 3.0.2 (Default branch) iBot Software Releases - RSS News 0 12-30-2008 10:10 PM
Dada Mail 3.0.1 (Default branch) iBot Software Releases - RSS News 0 11-26-2008 03:10 PM
Dada Mail 3.0.1 (Development branch) iBot Software Releases - RSS News 0 11-11-2008 12:10 PM
Installing Dada engine cptj UNIX for Dummies Questions & Answers 2 08-31-2005 06:50 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 4 Weeks Ago
mik4us mik4us is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 3
No logro solucionar sacar el dia de la semana de una fecha dada.

Con este código pretendo sacar el dia de la semana dada una fecha como parametro
por ejemplo.

./dia 27 10 2009
El resultado saliera:
Martes


El problema es que cuando llego casi al final el lunes etsa representado por un 0. el martes por 1.. y quiero hacer un bucle if para sustituir el 0 por Lunes
de este modo


if [$dow -eq 0] then
echo -"Lunes"
else
fi

Pero todo el rato me da error
y no se porque.
¿Alguien me podria ayudar?
Gracias



#!/bin/sh

# ja fe ma ap ma ju ju ag se oc no de
set -A lasts 0 31 28 31 30 31 30 31 31 30 31 30 31


dia=$1
mes=$2
anyo=$3

#
# Get Day of Week of Jan 1
dow1=$(cal 1 $anyo | sed -n '3s/. //gp')
((dow1=7-dow1))

#
# Es año Bisiesto?
leap=0
if ((!(anyo%100))); then
((!(anyo%400))) && leap=1
else
((!(anyo%4))) && leap=1
fi

#
# Establecer numero de dias de Febrero
lasts[2]=28
((leap)) && lasts[2]=29

#
# calculate day of year
i=0
previous=0
while ((i < mes)) ; do
((previous=previous+lasts[i]))
((i=i+1))
done
((doy=previous+dia))

#
# Calculate day of week
((dow = (doy+dow1-1)%7 ))

#echo dow = $dow
echo diadelasemana=$dow


if [$dow -eq 0] then
echo -"Lunes"
else
echo "..ya seguiria con cada numero"
fi

exit 0

---------- Post updated at 08:17 AM ---------- Previous update was at 08:10 AM ----------

Sorry i didn't realize that I had to write in English

My problem is that i want to calculate the day of the week, i want to change result given as a number for the day.

I mean, the program now do that if the day is Monday is represented by 0, Tuesday by 1.. but i want the word "Monday" as a result. I thought in a bucle if but there is always a mistake and i dont know why.

Thank you
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0