diff options
| author | kre <kre@NetBSD.org> | 2023-02-24 19:04:54 +0000 |
|---|---|---|
| committer | kre <kre@NetBSD.org> | 2023-02-24 19:04:54 +0000 |
| commit | 099ef1b4e3973712427ffdc720317b2102a890db (patch) | |
| tree | 0371fc6b491cc0f221d9fc87c828251f6aa5c8bb /bin | |
| parent | a136ed1ef05f83a07f6051844534b97a1a600a73 (diff) | |
Allow (but do not require) the magic '--' option terminator in
the builtin 'alias' command. This allows portability (not that
anyone should really care with aliases) for scripts from other
shells in which the alias command has options, and the -- is
required to allow the first alias name to begin with a '-'.
That is, for us, alias -x='echo x' works fine, always has,
and still does. But other shells treat that as an attempt
to use the -x option (and maybe -= etc), and require
alias -- -x='echo x'. For us that variant used to complain
about the alias -- not existing (as an arg with no '=' is
treated as a request to extract the value of the alias).
Posix also generally requires all standard commands (or
which "alias" is one, unfortunately) to support '--' even
if they have no options, for precisely this reason.
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/sh/alias.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/bin/sh/alias.c b/bin/sh/alias.c index e0023ba2e70..7556f21e659 100644 --- a/bin/sh/alias.c +++ b/bin/sh/alias.c @@ -1,4 +1,4 @@ -/* $NetBSD: alias.c,v 1.21 2019/02/09 09:11:07 kre Exp $ */ +/* $NetBSD: alias.c,v 1.22 2023/02/24 19:04:54 kre Exp $ */ /*- * Copyright (c) 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)alias.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: alias.c,v 1.21 2019/02/09 09:11:07 kre Exp $"); +__RCSID("$NetBSD: alias.c,v 1.22 2023/02/24 19:04:54 kre Exp $"); #endif #endif /* not lint */ @@ -253,18 +253,20 @@ countaliases(void) } int -aliascmd(int argc, char **argv) +aliascmd(int argc, char **argv) /* ARGSUSED */ { char *n, *v; int ret = 0; struct alias *ap; - if (argc == 1) { + (void) nextopt(NULL); /* consume possible "--" */ + + if (*argptr == NULL) { list_aliases(); return 0; } - while ((n = *++argv) != NULL) { + while ((n = *argptr++) != NULL) { if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */ if ((ap = lookupalias(n, 0)) == NULL) { outfmt(out2, "alias: %s not found\n", n); |
