From owner-freebsd-questions@FreeBSD.ORG Wed Aug 31 18:49:15 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 E360A16A41F for ; Wed, 31 Aug 2005 18:49:15 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9038F43D48 for ; Wed, 31 Aug 2005 18:49:15 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.3) id j7VInFjp039792; Wed, 31 Aug 2005 13:49:15 -0500 (CDT) (envelope-from dan) Date: Wed, 31 Aug 2005 13:49:14 -0500 From: Dan Nelson To: Gary Kline Message-ID: <20050831184914.GD16354@dan.emsphone.com> References: <20050831181545.GA57907@thought.org> <20050831184205.GC16354@dan.emsphone.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050831184205.GC16354@dan.emsphone.com> X-OS: FreeBSD 5.4-STABLE X-message-flag: Outlook Error User-Agent: Mutt/1.5.9i Cc: 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:49:16 -0000 In the last episode (Aug 31), Dan Nelson said: > In the last episode (Aug 31), Gary Kline said: > > 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? > > > > #/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 > > zsh has the % modulo operator, so xmod=$(( x % n )) . Silly me, I forgot to read the source to /bin/sh's arithmetic code. It knows about % too, so $(( x % n )) will work anywhere. -- Dan Nelson dnelson@allantgroup.com