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?

link|improve this question

0% accept rate
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
feedback

4 Answers

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).

link|improve this answer
feedback

Try

 [ $MinuteNow -eq $i ]

See man test for more info.

link|improve this answer
feedback

In bash, use:

(( $MinuteNow == $i ))

as in:

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

If sh compatibility is needed, use:

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

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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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