Module Name: src Committed By: kre Date: Fri Feb 24 19:04:54 UTC 2023
Modified Files: src/bin/sh: alias.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/bin/sh/alias.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/alias.c diff -u src/bin/sh/alias.c:1.21 src/bin/sh/alias.c:1.22 --- src/bin/sh/alias.c:1.21 Sat Feb 9 09:11:07 2019 +++ src/bin/sh/alias.c Fri Feb 24 19:04:54 2023 @@ -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);