[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Comparison failure
From: |
Dave Rutherford |
Subject: |
Re: Comparison failure |
Date: |
Thu, 10 Jan 2008 09:36:54 -0500 |
On Jan 10, 2008 8:13 AM, Frans de Boer <frans@fransdb.nl> wrote:
> Following is a function which fails constantly.
[...]
> if [[ $i != -1 && $i < $((iPriTblCnt-1)) ]]; then
> echo $((i+1));
> else
> echo -1
> fi
Now, "[[" isn't very well documented, so I tend not to use it,
but notice how "<" behaves here. It looks like it's doing a string
comparison. Try "-lt" to get a numeric less-than.
> ------ Example trace 1 ->
[...]
> ++ [[ 5 < 54 ]]
> ++ echo 6
[...]
> ++ [[ 6 < 54 ]]
> ++ echo -1
[...]
> ------------- Example trace 2 ->
[...]
> ++ [[ 1 < 109 ]]
> ++ echo 2
[...]
> ++ [[ 2 < 109 ]]
> ++ echo -1
Regards,
Dave
- Comparison failure, Frans de Boer, 2008/01/10
- Re: Comparison failure,
Dave Rutherford <=
- Message not available
Re: Comparison failure, Pierre Gaston, 2008/01/10