In my continuing series of things you already know, unless you don’t, today I learned of an alternative to printing strings in the shell, sans newline.
I was reading the FreeBSD
sh(1) manpage, like a gentleman:
echo [-e | -n] [string ...] Print a space-separated list of the arguments to the standard output and append a newline character. -n Suppress the output of the trailing newline.
$ echo saywhat ==> saywhat ==> $
$ echo -n saywhat ==> saywhat$
This whole time I’d been doing this to avoid a newline:
$ printf '%s' saywhat
Good ol' Kenneth Almquist, and the FreeBSD maintainers :).
But does this also apply to csh, the shell and scripting language allegedly considered harmful, and therefore you should write in? Under
echo_style in the
bsd Don't echo a newline if the first argument is `-n`; the default for csh.