Fix illegal exit code -1

It was one more overlooked bashism that leaded to a warning in dash:

  exit: Illegal number: -2
Get rid of useless use of cat
Lowercase names of not exported variables
Shorten conditionals
Optimize loop