I would say that the safest option is to print the results without a new line since when the command is piped to another command which doesn't expect its input to be line separated you may run into troubles, like the following script:
function test_nl {
echo result
}
function test_no_nl {
printf %s result
}
test_nl | xxd -p | wc -c
#prints 15
test_no_nl | xxd -p | wc -c
#prints 13
Are there any cases where the test_nl approach is better?
test_no_nl(){ ... }
syntax is better still. A two character answer to your question is no. – icarus Nov 14 '20 at 15:30foo() { ... }
is POSIX-portable, whilefunction foo { ... }
isn't. – JoL Nov 14 '20 at 23:34