From c9ca0ff531f1f48b5114eb84c456ab5b70e37b02 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 28 Nov 2021 00:11:23 +0100 Subject: [PATCH] typeset equivalents: use 'typeset' in error messages (re: 1fbbeaa1) When giving an invalid or incompatible option to a typeset option equivalent command (former default alias) such as 'compound' or 'integer', the resulting usage messages are incorrect. Example: $ ksh -c 'compound -T foo=(typeset -a bar[1]=23)' ksh: compound: -T cannot be used with other options Usage: compound [-bflmnprstuxACHS] [-a[[type]]] [-i[base]] [-E[n]] [-F[n]] [-L[n]] [-M[mapping]] [-R[n]] [-X[n]] [-h string] [-T[tname]] [-Z[n]] [name[=value]...] Or: compound -f [name...] Or: compound -m [name=name...] Or: compound -n [name=name...] Or: compound -T [tname[=(type definition)]...] Help: compound [ --help | --man ] 2>&1 The error message is wrong (there were no other options) and some of the listed usages are invalid, like 'compound -f'. Typeset option equivalent commands should just use 'typeset' in all their error messages to avoid confusion. This is done by setting error_info.id to the name of the typeset builtin. --- src/cmd/ksh93/bltins/typeset.c | 2 +- src/cmd/ksh93/tests/builtins.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index eaf0fda55..968e4ec4b 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -221,7 +221,7 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context) else if(argv[0][0] != 't') /* not ypeset */ { char **new_argv = (char **)stakalloc((argc + 2) * sizeof(char*)); - new_argv[0] = "typeset"; + error_info.id = new_argv[0] = SYSTYPESET->nvname; if(argv[0][0] == 'a') /* utoload == typeset -fu */ new_argv[1] = "-fu"; else if(argv[0][0] == 'c') /* ompound == typeset -C */ diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index 32bcbc7d0..3eebd96d4 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -1039,6 +1039,8 @@ do case $bltin in actual=$({ PATH=${bltin%/*}; "${bltin##*/}" --this-option-does-not-exist; } 2>&1) ;; */*) err_exit "strange path name in 'builtin' output: $(printf %q "$bltin")" continue ;; + autoload | compound | float | functions | integer | nameref) + bltin=typeset ;& *) expect="Usage: $bltin " actual=$({ "${bltin}" --this-option-does-not-exist; } 2>&1) ;; esac