Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

MinuteNow=date +%M;

for ((i=2;i<=57;i+=5))
        if [ "$MinuteNow" == "$i" ]; then

The problem is for 2 and 7, the date commande output is 02 and 07 but the variable $i is 2 and 7... I tried to add a condition to change only these 2, but it was bugging the loop...

Can you give me a tip please?

share|improve this question
Unix is an operating system. Saying "how do I do X in a Unix script" is like "how do I do X in a Windows programming language" without telling which of the hundred languages you use. – grawity Feb 22 '11 at 13:59

Use "-eq" to compare numbers, then you wont have this problems:

if [ "$MinuteNow" -eq "$i" ]; then

should do it.

(there are lots of other possibilities, being ${MinuteNow#0} another simple one, but I thing using the right operator -eq instead of == is the better one).

share|improve this answer

In Bash, you will need to force the string to base 10:

if (( 10#$MinuteNow == i ))    # you can omit the dollar sign on bare variables in this context

In the Bourne shell (sh):

if [ $MinuteNow -eq $i ]

In zsh or ksh93:

if (( MinuteNow == i ))    # you can omit the dollar sign on bare variables in this context
share|improve this answer


 [ $MinuteNow -eq $i ]

See man test for more info.

share|improve this answer

In bash, use:

(( $MinuteNow == $i ))

as in:

if (( $MinuteNow == $i )); then

If sh compatibility is needed, use:

[ "$MinuteNow" -eq "$i" ]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.