|
| From: | Adam Rosenwald |
| Subject: | Re: [PATCH] Fix bug when attempting to echo special sequences literally. -- [RESUBMISSION] |
| Date: | Thu, 13 Mar 2008 02:03:33 -0400 |
| User-agent: | Thunderbird 2.0.0.12 (Macintosh/20080213) |
I left out some <very important> curly braces. Here's the working patch:
=== BEGIN PATCH ===
--- echo.c.orig 2008-03-13 01:59:22.000000000 -0400
+++ echo.c 2008-03-13 01:59:37.000000000 -0400
@@ -145,6 +145,7 @@
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION,
usage, AUTHORS, (char const *) NULL);
+ char first=1;
--argc;
++argv;
@@ -154,6 +155,15 @@
char const *temp = argv[0] + 1;
size_t i;
+ if (first == 1) {
+ first = 0;
+ if (temp[0] == '-') {
+ --argc;
+ ++argv;
+ goto just_echo;
+ }
+ }
+
/* If it appears that we are handling options, then make sure that
all of the options specified are actually valid. Otherwise, the
string should just be echoed. */
=== END PATCH ===
Adam Rosenwald wrote:
Try using echo to output the string '-e' or '-E' or '-n' literally. You can't. Furthermore try executing `echo -e [-eEn]...`. Nothing but a blank line.The patch below utilizes a familiar technique (used, e.g., in grep) to escape arguments; however, admittedly it can be rendered more elegant. :)This was patched against the 03/12/08 coreutils GIT version; however, echo.c doesn't appear to have changed substantively for years.=== BEGIN PATCH === --- echo.c.orig 2008-03-13 01:33:08.000000000 -0400 +++ echo.c 2008-03-13 01:35:04.000000000 -0400 @@ -145,6 +145,7 @@ parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, usage, AUTHORS, (char const *) NULL); + char first=1; --argc; ++argv; @@ -154,6 +155,14 @@ char const *temp = argv[0] + 1; size_t i; + if (first == 1) { + first = 0; + if (temp[0] == '-') + --argc; + ++argv; + goto just_echo; + } + /* If it appears that we are handling options, then make sure that all of the options specified are actually valid. Otherwise, the string should just be echoed. */ === END PATCH === Regards, - A.
| [Prev in Thread] | Current Thread | [Next in Thread] |