bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

suggestion: shell option for echo to not interpret any argument as an op


From: Zachary Santer
Subject: suggestion: shell option for echo to not interpret any argument as an option
Date: Wed, 26 Jul 2023 08:42:15 -0400

bash's echo command is broken - YouTube
<https://www.youtube.com/watch?v=lq98MM2ogBk>

To restate what's in the video, you can't safely use echo to print the
contents of a variable that could be arbitrary, because the variable could
consist entirely of '-n', '-e', or '-E', and '--' is not interpreted as the
end of options, but rather, something to print.

I recognized this and replaced all of my calls to echo with printf some
time ago.

If POSIX mandates that '--' not be taken as the end of options, then the
safe thing would be to simply not have echo take any options. Obviously,
that would break backwards compatibility, so you'd want this to be optional
behavior that the shell programmer can enable if desired.

I guess, alternatively, there could be a shell option for echo to interpret
'--' as the end of options. However, this would require more work on the
part of whoever may be trying to resolve this issue in their scripts.

Just a thought.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]