bug-bash
[Top][All Lists]
Advanced

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

Re: suggestion: shell option for echo to not interpret any argument as a


From: Greg Wooledge
Subject: Re: suggestion: shell option for echo to not interpret any argument as an option
Date: Wed, 26 Jul 2023 09:12:30 -0400

On Wed, Jul 26, 2023 at 08:42:15AM -0400, Zachary Santer wrote:
> 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.

Yes.  Sounds like you're already aware of the issue, and already know
how to fix it in your scripts.

> 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.

Everyone who does shell scripts on a regular basis is already aware of
all these issues, and the consensus is "stop using echo with variable
content".  There's really nothing more to be said at this point.
Adding more shell options wouldn't simplify anything.  It would just
add yet another permutation to the problem.



reply via email to

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