Skip to content

Conversation

@eli-schwartz
Copy link
Contributor

The "echo" command was soft-deprecated from the shell programming language in ~1992. There is no way to use it correctly if:

  • the "-e" or "-n" or "-E" or any other options are used
  • backslash escape sequences are used
  • the printed string contains shell variables containing either of the above

In recognition of the fact that echo was historically used in many scripts, some of which avoided these issues and therefore succeeded when run, the "echo" command was NOT marked as obsolescent, out of fear that marking it as obsolescent would lead to vendors removing "echo" entirely and breaking existing scripts (or at least, the subset of scripts which managed to work correctly).

However, it is warned against, that after 1992 you should avoid writing new code that uses "echo" and instead use "printf".

printf has an actual definition of its behavior, which echo did not, and that behavior is to interpret backslash escapes in the first parameter, which is necessary by this Makefile.am in order to embed newlines into the generated libtool file. Simply replacing "echo -e" with "printf" will therefore correctly and reliably do the intended functionality. We also add one final embedded newline to avoid producing a file without an end-of-line character on the last line of the file.

Fixes: #257

The "echo" command was soft-deprecated from the shell programming
language in ~1992. There is no way to use it correctly if:

- the "-e" or "-n" or "-E" or any other options are used
- backslash escape sequences are used
- the printed string contains shell variables containing either of the
  above

In recognition of the fact that echo was historically used in many
scripts, some of which avoided these issues and therefore succeeded when
run, the "echo" command was NOT marked as obsolescent, out of fear that
marking it as obsolescent would lead to vendors removing "echo" entirely
and breaking existing scripts (or at least, the subset of scripts which
managed to work correctly).

However, it is warned against, that after 1992 you should avoid writing
new code that uses "echo" and instead use "printf".

printf has an actual definition of its behavior, which echo did not, and
that behavior is to interpret backslash escapes in the first parameter,
which is necessary by this Makefile.am in order to embed newlines into
the generated libtool file. Simply replacing "echo -e" with "printf"
will therefore correctly and reliably do the intended functionality. We
also add one final embedded newline to avoid producing a file without an
end-of-line character on the last line of the file.

Fixes: ckolivas#257
Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
@ckolivas ckolivas merged commit 1242aec into ckolivas:master Feb 6, 2025
1 check failed
@eli-schwartz eli-schwartz deleted the dont-use-echo branch July 27, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bashism in Makefile.am

2 participants