[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: |
Kerin Millar |
Subject: |
Re: suggestion: shell option for echo to not interpret any argument as an option |
Date: |
Wed, 26 Jul 2023 15:25:41 +0100 |
User-agent: |
Cyrus-JMAP/3.9.0-alpha0-592-ga9d4a09b4b-fm-defalarms-20230725.001-ga9d4a09b |
On Wed, 26 Jul 2023, at 1:42 PM, Zachary Santer wrote:
> 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.
echo() { local IFS=' '; printf '%s\n' "$*"; }
--
Kerin Millar
Re: suggestion: shell option for echo to not interpret any argument as an option,
Kerin Millar <=
Re: suggestion: shell option for echo to not interpret any argument as an option, Zachary Santer, 2023/07/26