Re: Doing a modulo in /bin/sh??

From: Gary Kline (kline_at_tao.thought.org)
Date: 08/31/05

  • Next message: Dan Nelson: "Re: Doing a modulo in /bin/sh??"
    Date: Wed, 31 Aug 2005 11:35:28 -0700
    To: Philip Hallstrom <freebsd@philip.pjkh.com>
    
    

    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
    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
    

  • Next message: Dan Nelson: "Re: Doing a modulo in /bin/sh??"

    Relevant Pages

    • Re: Need to remove a ghost file, but cant because it doesnt exist
      ... The only somewhat "special" characters in it are a comma, ... $ echo 1141914051.* ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)
    • Re: diff files matching a pattern
      ... The size really doesn't matter for those extra large files. ... # pattern must be in double quotes to avoid shell expasion ... echo $co files compared. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)
    • Re: bash scripting q
      ... It pumps the elapsed time to stdout. ... How do I use that $a in command parameters, ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)
    • Re: how to exclude the packges in dist-upgrade
      ... echo "you're not root, go away." ... So in your case, as root: ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)
    • Re: PATH question
      ... On 15.03.07 11:02, Celejar wrote: ... ~$ echo $path ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
      (Debian-User)