Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Trailing newlines are removed in backtick and $(..) substitution per POSIX:

> The shell shall expand the command substitution by executing command in a subshell environment (see Shell Execution Environment) and replacing the command substitution (the text of command plus the enclosing "$()" or backquotes) with the standard output of the command, removing sequences of one or more <newline> characters at the end of the substitution. Embedded <newline> characters before the end of the output shall not be removed; however, they may be treated as field delimiters and eliminated during field splitting, depending on the value of IFS and quoting that is in effect. If the output contains any null bytes, the behavior is unspecified.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...

I don't know of any shell that doesn't follow that.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: