Doing a modulo in /bin/sh??

Philip Hallstrom freebsd at philip.pjkh.com
Wed Aug 31 18:19:06 GMT 2005


> 	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 at foxtrot:~ 
% expr 1 % 2
1
philip at foxtrot:~ 
% expr 2 % 2
0



More information about the freebsd-questions mailing list