sh-code portability improvements and fixes

use export without assignment

delete needless quoting (after case, in assignments, ...)

add missing quoting (on the echo command line, ...)

make sure 'test =' is not called with empty arguments

do not call test with more than 4 arguments