Date: Wed, 31 Aug 2005 11:35:28 -0700 From: Gary Kline <kline@tao.thought.org> To: Philip Hallstrom <freebsd@philip.pjkh.com> Cc: Gary Kline <kline@tao.thought.org>, FreeBSD Mailing List <freebsd-questions@FreeBSD.ORG> Subject: Re: Doing a modulo in /bin/sh?? Message-ID: <20050831183528.GA58621@thought.org> In-Reply-To: <20050831111755.V2009@wolf.pjkh.com> References: <20050831181545.GA57907@thought.org> <20050831111755.V2009@wolf.pjkh.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050831183528.GA58621>