lundi 29 juin 2015

One line if statement in bash

I've never programed in bash... yet I'm trying to solve a problem for an anchievement in a game (cogingame.com)

I have the following code:

for (( i=0; i<N-1; i++ )); do
   tmp=$(( sorted_array[i+1] - sorted_array[i] ));
   if [ $tmp < $result ]; then result=$tmp fi
done

And this error: /tmp/Answer.sh: line 42: syntax error near unexpected token done' at Answer.sh. on line 42 /tmp/Answer.sh: line 42:done' at Answer.sh. on line 42

I want to compare adjacent values of my array and store the minimun diference between them... but I cant figure how to do an If statement in bash

Aucun commentaire:

Enregistrer un commentaire