Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: fix incorrect use of shell commands in handmade libtool file #258

Merged
merged 1 commit into from
Feb 6, 2025

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 <[email protected]>
@ckolivas ckolivas merged commit 1242aec into ckolivas:master Feb 6, 2025
1 check failed
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