Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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))
do
        if [ "$MinuteNow" == "$i" ]; then
                *************
        fi
done

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
1  
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

Try

 [ $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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .