I apologize in advance for the verbose answer, but you will see that there are a lot of things to consider.
Your code, as posted, has some syntax errors ...
While the assignment to myvar is done without the dollar-sign (as you have shown), all other references to it must start with dollar-sign.
The right bracket needs a preceding space.
The "fi" should not be followed by a period.
Also, any time that a variable could be zero length or all spaces, your variable references should be enclosed in double-quotes as a place-holder so as not to produce a syntax error. As an example, the statement:
if [ $myvar = 0 ]
could end up looking like:
if [ = 0 ]
which is now lacking a test argument, but enclosing in quotes keeps it valid syntax:
if [ "" = 0 ]
Now we need to talk about the actual test. You did not show how you captured myvar, and it makes a big difference. I will discuss the following three ways:
1. myvar=`awk ... `
2. awk ... | read myvar
3. awk ... | read myvar morewords
#1 will capture the full 5 characters pulled by substr, including any leading, embedded and trailing spaces. This web page will condense multiple consecutive spaces down to a single space. That first entry is really one zero followed by four spaces:
"0 "
"00000"
"000 "
" 000 "
" 0 0 "
#2 approach will discard any leading or trailing spaces, but keeps embedded spaces, so you would capture:
"0"
"00000"
"000"
"000"
"0 0"
#3 will capture the first space-delimited word only, so you would capture:
"0"
"00000"
"000"
"000"
"0"
Now consider these two types of test:
if [ "$myvar" = 000 ]
if [ "$myvar" -eq 0 ]
The first test is an alphanumeric test, and will test true only if precisely the same, including leading and trailing spaces. For example, if you captured "000 " in $myvar, to test true you would have to do:
if [ "$myvar" = "000 " ]
But a numeric test will test true whether $myvar is 0 or 00 or 000 etc:
if [ "$myvar" -eq 0 ]
But while this gives you the convenience of a numeric equivalence test, this test is more sensitive to syntax. If $myvar is more than one word, such as "0 0", it will see it as:
if [ 0 0 -eq 0 ]
and you will get "syntax error". And if $myvar contains a non-digit, you will get "bad number".
Before testing with -eq, if you want to ensure that $myvar is all digits (one or more), the following expression should show greater than zero (zero would indicate either null or non-digits):
expr "$myvar" : "[0-9]*$"
and if null is OK, following expression should show greater than zero for either null or all digits (zero would indicate non-digits):
expr "9$myvar" : "[0-9]*$"