From owner-freebsd-questions@FreeBSD.ORG Wed Aug 31 18:35:30 2005 Return-Path: X-Original-To: freebsd-questions@FreeBSD.ORG Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8F06F16A41F for ; Wed, 31 Aug 2005 18:35:30 +0000 (GMT) (envelope-from kline@tao.thought.org) Received: from tao.thought.org (dsl231-043-140.sea1.dsl.speakeasy.net [216.231.43.140]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0A67C43D46 for ; Wed, 31 Aug 2005 18:35:29 +0000 (GMT) (envelope-from kline@tao.thought.org) Received: from tao.thought.org (localhost [127.0.0.1]) by tao.thought.org (8.13.1/8.13.1) with ESMTP id j7VIZSEr059010; Wed, 31 Aug 2005 11:35:28 -0700 (PDT) (envelope-from kline@tao.thought.org) Received: (from kline@localhost) by tao.thought.org (8.13.1/8.13.1/Submit) id j7VIZSDR059009; Wed, 31 Aug 2005 11:35:28 -0700 (PDT) (envelope-from kline) Date: Wed, 31 Aug 2005 11:35:28 -0700 From: Gary Kline To: Philip Hallstrom Message-ID: <20050831183528.GA58621@thought.org> References: <20050831181545.GA57907@thought.org> <20050831111755.V2009@wolf.pjkh.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050831111755.V2009@wolf.pjkh.com> User-Agent: Mutt/1.4.2.1i X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: Observing 19 years of service to the Unix community Cc: Gary Kline , FreeBSD Mailing List Subject: Re: Doing a modulo in /bin/sh?? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Aug 2005 18:35:30 -0000 On Wed, Aug 31, 2005 at 11:18:57AM -0700, Philip Hallstrom wrote: > > I can grab the results of "w=$date+%U)"; in C an use the modulo > > operator; is there a way to do this is /bin/sh? ot zsh? > > > > tia, guys, > > > > gary > > > >#/bin/sh > >w=$(date +%U) > >echo "w is $w"; > >(even=$(w % 2 )); ## flubs. > >echo "even is $even"; ## flubs. > > > >if [ $even -eq 0 ] ## flubs, obv'ly. > >then > > echo "week is even"; > >else > > echo "week is odd"; > >fi > > Take a look at 'expr'.... > > philip@foxtrot:~ > % expr 1 % 2 > 1 > philip@foxtrot:~ > % expr 2 % 2 > 0 Thankee, sir; I forgot that with ash/sh/<&c>, y'gotta use expr; and inside backticks in cases like this one. gary #/bin/sh w=$(date +%U) echo "w is $w"; even=`expr ${w} % 2`; echo "even is $even"; if [ $even -eq 0 ] then echo "week is even"; else echo "week is odd"; fi -- Gary Kline kline@thought.org www.thought.org Public service Unix