V
V
Viktor Taran2017-12-06 23:42:38
linux
Viktor Taran, 2017-12-06 23:42:38

Linux can't count to 10?

Today I encountered a very strange thing
. The essence of the task was quite simple to throw sharp spikes in the number of letters in the queue into the monitoring system.
I quickly threw in the rule
test "99" \> "$(mailq|wc -l)"; echo $?, in fact, it is a little more complicated there, but this does not change the essence.
And so the chip is in what
If $(mailq|wc -l)= "15", then the calculation will work correctly BUT only before the appearance of a new register 100 will already issue a status 0 or if you change the sign in the other direction, then 1but not from the numbers
1000 and so on the same
Actually we check the value variable

[email protected] ~ $ mailq|wc -l
49971

And here is what test returns
[email protected] ~ $ test "99" \> "$(mailq|wc -l)"; echo $?
0
[email protected] ~ $ test "9999" \> "$(mailq|wc -l)"; echo $?
0
[email protected] ~ $ test "99999" \> "$(mailq|wc -l)"; echo $?
0
[email protected] ~ $ test "999999" \> "$(mailq|wc -l)"; echo $?
0
[email protected] ~ $ test "999999" \< "$(mailq|wc -l)"; echo $?
1
[email protected] ~ $ test "99999" \< "$(mailq|wc -l)"; echo $?
1
[email protected] ~ $ test "9999" \< "$(mailq|wc -l)"; echo $?
1
[email protected] ~ $ test "999" \< "$(mailq|wc -l)"; echo $?
1
[email protected] ~ $ test "99" \< "$(mailq|wc -l)"; echo $?
1
[email protected] ~ $ test "9" \< "$(mailq|wc -l)"; echo $?
1

And one could assume that something is not working, but the trick is that up to 99 everything is considered normal (when the value of the variable is less than 100)
1. Why is this
2. what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-12-07
@shambler81

Read man

test 99 > 100; echo $?
0

test 99 -gt 100; echo $?
1

The primitives =, !=, <, > are used to compare strings
. Their equivalents -eq, -ne, -lt, -gt are used to compare numbers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question