On POSIX, echo does not support any parameters.
Therefore, when echo -n starts with sh , it outputs the literal -n instead of interpreting -n as the no-trailing-newline option:
$ sh -c 'echo -n "apple"' -n apple
Note. Not all sh implementations behave this way; some, for example, on Ubuntu (where dash acts like sh ), support the -n option, but the fact is that you cannot rely on this if your code should work on multiple platforms.
A portable POSIX-compatible way to print to stdout is to use the printf utility :
printf %s "apple" | shasum -a 256
mklement0
source share