by benjaminwai · 3y ago · 0 comments
$ echo -n "abcde" |base64
Otherwise, without the -n, echo injects an extra newline character to the end of the string that would become encoded.(however, the parent's use of "echo" would be fine as it's not using a variable and so won't be interpreting a dash as an extra option etc)
[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/e...
I just tested it out with:
sh /bin/echo -n "test"
/bin/echo: 3: Syntax error: "(" unexpected
I didn't realise until recently that printf can also replace a lot of uses of the "date" command which is helpful with logging as it avoids calling an external command for every line logged.printf is always the better choice.