[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#14115: [PATCH] echo: adding support for '--' in option parsing
From: |
Hemmo Nieminen |
Subject: |
bug#14115: [PATCH] echo: adding support for '--' in option parsing |
Date: |
Mon, 1 Apr 2013 12:49:52 +0300 |
A '--' can now be used to mark the end of echo's options that should be
parsed. This makes it possible to e.g. print lines where the first
argument matches some of echo's options (e.g. 'echo -- -e').
---
src/echo.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/echo.c b/src/echo.c
index 58e6975..6f76d1b 100644
--- a/src/echo.c
+++ b/src/echo.c
@@ -39,7 +39,7 @@ usage (int status)
else
{
printf (_("\
-Usage: %s [SHORT-OPTION]... [STRING]...\n\
+Usage: %s [SHORT-OPTION]... [--] [STRING]...\n\
or: %s LONG-OPTION\n\
"), program_name, program_name);
fputs (_("\
@@ -59,6 +59,8 @@ Echo the STRING(s) to standard output.\n\
fputs (VERSION_OPTION_DESCRIPTION, stdout);
fputs (_("\
\n\
+A '--' can be used to mark the end of SHORT-OPTIONs.\n\
+\n\
If -e is in effect, the following sequences are recognized:\n\
\n\
"), stdout);
@@ -149,6 +151,12 @@ main (int argc, char **argv)
char const *temp = argv[0] + 1;
size_t i;
+ if (temp[0] == '-' && temp[1] == '\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. */
--
1.8.2
- bug#14115: [PATCH] echo: adding support for '--' in option parsing,
Hemmo Nieminen <=