commit: e4d1d4005ade9f2d881864589fe4df64e4bc6281
parent f85faf60cc03aeda893594dd829e5fba54f1cd03
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 26 Mar 2025 23:46:07 +0100
cmd/echo: also output '-' as-is
Diffstat:
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/cmd/echo.c b/cmd/echo.c
@@ -22,8 +22,8 @@ main(int argc, char *argv[])
{
if(argv[0][0] != '-') break;
- /* '--' needs to be passed as-is so no argc--,argv++ */
- if(argv[0][1] == '-') break;
+ /* '-' and '--' needs to be passed as-is so no argc--,argv++ */
+ if(argv[0][1] == '\0' || (argv[0][1] == '-' && argv[0][2] == '\0')) break;
for(int i = 1; argv[0][i] != '\0'; i++)
{
diff --git a/test-cmd/echo.sh b/test-cmd/echo.sh
@@ -4,7 +4,7 @@
WD="$(dirname "$0")/../"
target="${WD}/cmd/echo"
-plans=17
+plans=19
. "$(dirname "$0")/tap.sh"
t 'empty' '' '
@@ -19,6 +19,12 @@ t -- '-n foo' '-n foo' 'foo'
t -- '-n foo bar' '-n foo bar' 'foo bar'
t -- '-n -- foo' '-n -- foo' '-- foo'
+t dash - '-
+'
+
+t double-dash -- '--
+'
+
wrap_od() {
"$target" "$@" \
| od -An -t x1 \