I was writing some "if then" statements and found what seemed to me an odd behavior. Upon investigation I realized that it boiled down to the exit code of the comparison I was making. I illustrate my findings in the following code snippet.
As you can see
rc=1 [ $rc -eq 0 ] es_num=$? [ $rc=0 ] es_str=$? echo "es_num is $es_num" echo "es_str is $es_str"
es_num is 1 es_str is 0
Is there any documentation, preferably from the POSIX standards, that talks about the difference in the exit statuses of
= in a test construct?
What should I be aware of when writing conditional statements? What are some best practices regarding this?
Portable code is preferable to Bash code (which I'm using).