replaced echo by printf which seems to be more reliable in terms of newline-at-the-end-of-file handling
replace echo by printf
minor script modifications