From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ns1.sunset.net ([205.161.255.5] helo=onyx.sunset.net) by speech.braille.uwo.ca with esmtp (Exim 3.36 #1 (Debian)) id 1DH8jz-0008Th-00 for ; Thu, 31 Mar 2005 18:06:19 -0500 Received: from sunset.net (208-53-84-159.chico.ca.digitalpath.net [208.53.84.159]) by onyx.sunset.net (8.12.10/8.12.10) with ESMTP id j2VN3HWi005156 for ; Thu, 31 Mar 2005 15:03:17 -0800 Received: (from rreid@localhost) by sunset.net (8.13.3/8.12.8/Submit) id j2VN6C7a002402 for speakup@braille.uwo.ca; Thu, 31 Mar 2005 15:06:12 -0800 Date: Thu, 31 Mar 2005 15:06:12 -0800 From: "Ralph W. Reid" To: "Speakup is a screen review system for Linux." Message-ID: <20050331230612.GA2260@sunset.net> References: <000801c53493$fbd20890$4e31e444@nedelko83f1172> <20050330201653.GA18561@sunset.net> <008301c5357a$892961c0$4e31e444@nedelko83f1172> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <008301c5357a$892961c0$4e31e444@nedelko83f1172> User-Agent: Mutt/1.4.2.1i Subject: Re: how to get the last word from file X-BeenThere: speakup@braille.uwo.ca X-Mailman-Version: 2.1.5 Precedence: list Reply-To: "Speakup is a screen review system for Linux." List-Id: "Speakup is a screen review system for Linux." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2005 23:06:19 -0000 As you have probably seen, others have posted _much_ simpler solutions to this problem than I did. There is a `case` statement in bash, but you would have to determine how to check for different values while performing only a single `cal` command. See your favorite man page for bash by running `man bash` on your favorite linux box--it is big, but there is a lot of good stuff in there. As a side note, you might be able to use a simple word count to get the days in any given month since `cal` should always produce the same headings, and then a range of numbers ranging from 28 through 31 depending on the month and whether or not the month is February during a leap year. The following seems to work, and uses the math feature available in `bash` to assign the result to a variable, and then echos the result for output: let totaldays=`cal | wc -w`-9 echo $totaldays There should always be 9 words of header info produced by `cal`, so subtracting the count of the words in the header (9) leaves the number of dates displayed for the month. I might have recognized this way of producing the total days if I had slept a little before posting the somewhat lengthy and complicated solution shown below--maybe next time I will not be so hasty with my post if it seems a little messy again;). Just one more of many possible ways of producing the output you seem to be looking for :) . HTH, and have a _great_ day! On Wed, Mar 30, 2005 at 03:48:02PM -0700, Ned wrote: > This is yet to be seen! > Wow, what a syntax. > semicolon at the end of if, elif, then, > and the most apealing is that fi at the end. > Thanks a lot! > It's a totally new stuff to me. > Is there a case structure in bash? That would fit here just perfectly. > > Many thanks! > Ned > ----- Original Message ----- > From: "Ralph W. Reid" > To: "Speakup is a screen review system for Linux." > Sent: Wednesday, March 30, 2005 1:16 PM > Subject: Re: how to get the last word from file > > > >On Tue, Mar 29, 2005 at 12:17:43PM -0700, Ned wrote: > >>Hi list, > >>I am using the cal command to get current month. What I need for my shell > >>script is how many days are there in the current month, that is, the last > >>listed date for that month is that very number. > >>How can I get that number? > >>cal | tail -1 > >>and then what? > >> > >>Many thanks! > >>Ned > > > >The above command line will produce a blank line because the last line > >produced by `cal` is a blank line. If you are looking specifically > >for days in the current month (as opposed to a more general > >last-word-in file search), the following is one of several ways to > >produce it: > > > >if [ `cal | grep -c 31` == 1 ]; > >then > >echo 31 > >elif [ `cal | grep -c 30` == 1 ]; > >then > >echo 30 > >elif [ `cal | grep -c 29` == 1 ]; > >then > >echo 29 > >elif [ `cal | grep -c 28` == 1 ]; > >then > >echo 28 > >else > >echo Cal did not produce a calendar. > >fi > > > >HTH, and have a _great_ day! > > > >-- > >Ralph. N6BNO. Wisdom comes from central processing, not from I/O. > >rreid@sunset.net http://personalweb.sunset.net/~rreid > >...passing through The City of Internet at the speed of light! > >_PI = 4 * ARCTAN (1) -- Ralph. N6BNO. Wisdom comes from central processing, not from I/O. rreid@sunset.net http://personalweb.sunset.net/~rreid ...passing through The City of Internet at the speed of light! 1 = x^0