summaryrefslogtreecommitdiff
path: root/bin/ksh
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2018-05-18 13:25:21 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2018-05-18 13:25:21 +0000
commitcd64f03d92415002e889b7bd4356414ae828fd71 (patch)
tree3f5947ed9f280b7a70f4ff82a63bde2ef593a60f /bin/ksh
parente6403cabe6a1e73c5b021b3b624119ea78f8a39d (diff)
remove the alias type='whence -v' and replace it with
a buildin command, that just calls into c_whence(). This makes type look like the buildin in other shells and makes things like system("'type' 'git'"); work. With lots of suggestions and feedback from anton@, kn@ and jca@. ok kn@ jca@
Diffstat (limited to 'bin/ksh')
-rw-r--r--bin/ksh/c_ksh.c32
-rw-r--r--bin/ksh/ksh.111
-rw-r--r--bin/ksh/main.c3
-rw-r--r--bin/ksh/sh.h3
4 files changed, 38 insertions, 11 deletions
diff --git a/bin/ksh/c_ksh.c b/bin/ksh/c_ksh.c
index 327f627dc41..89b7a9c5545 100644
--- a/bin/ksh/c_ksh.c
+++ b/bin/ksh/c_ksh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_ksh.c,v 1.60 2018/04/09 17:53:36 tobias Exp $ */
+/* $OpenBSD: c_ksh.c,v 1.61 2018/05/18 13:25:20 benno Exp $ */
/*
* built-in Korn commands: c_*
@@ -410,9 +410,26 @@ c_whence(char **wp)
int pflag = 0, vflag = 0, Vflag = 0;
int ret = 0;
int optc;
- int iam_whence = wp[0][0] == 'w';
+ int iam_whence;
int fcflags;
- const char *options = iam_whence ? "pv" : "pvV";
+ const char *options;
+
+ switch (wp[0][0]) {
+ case 'c': /* command */
+ iam_whence = 0;
+ options = "pvV";
+ break;
+ case 't': /* type */
+ vflag = 1;
+ /* FALLTHROUGH */
+ case 'w': /* whence */
+ iam_whence = 1;
+ options = "pv";
+ break;
+ default:
+ bi_errorf("builtin not handled by %s", __func__);
+ return 1;
+ }
while ((optc = ksh_getopt(wp, &builtin_opt, options)) != -1)
switch (optc) {
@@ -430,7 +447,6 @@ c_whence(char **wp)
}
wp += builtin_opt.optind;
-
fcflags = FC_BI | FC_PATH | FC_FUNC;
if (!iam_whence) {
/* Note that -p on its own is dealt with in comexec() */
@@ -530,6 +546,13 @@ c_command(char **wp)
return c_whence(wp);
}
+int
+c_type(char **wp)
+{
+ /* Let c_whence do the work. type = command -V = whence -v */
+ return c_whence(wp);
+}
+
/* typeset, export, and readonly */
int
c_typeset(char **wp)
@@ -1392,6 +1415,7 @@ const struct builtin kshbuiltins [] = {
{"print", c_print},
{"pwd", c_pwd},
{"*=readonly", c_typeset},
+ {"type", c_type},
{"=typeset", c_typeset},
{"+unalias", c_unalias},
{"whence", c_whence},
diff --git a/bin/ksh/ksh.1 b/bin/ksh/ksh.1
index ceb3bce1264..fe425f7c611 100644
--- a/bin/ksh/ksh.1
+++ b/bin/ksh/ksh.1
@@ -1,8 +1,8 @@
-.\" $OpenBSD: ksh.1,v 1.198 2018/02/06 15:13:32 schwarze Exp $
+.\" $OpenBSD: ksh.1,v 1.199 2018/05/18 13:25:20 benno Exp $
.\"
.\" Public Domain
.\"
-.Dd $Mdocdate: February 6 2018 $
+.Dd $Mdocdate: May 18 2018 $
.Dt KSH 1
.Os
.Sh NAME
@@ -858,8 +858,6 @@ The following command aliases are defined automatically by the shell:
.Ic r Ns ='fc -s'
.It
.Ic stop Ns ='kill -STOP'
-.It
-.Ic type Ns ='whence -v'
.El
.Pp
Tracked aliases allow the shell to remember where it found a particular
@@ -4075,6 +4073,11 @@ traps in functions are not yet implemented.
.It Ic true
A command that exits with a zero value.
.Pp
+.It Ic type
+Short form of
+.Ic whence Fl v
+(see below).
+.Pp
.It Xo
.Ic typeset
.Oo
diff --git a/bin/ksh/main.c b/bin/ksh/main.c
index 047c9849e3b..3380d85badb 100644
--- a/bin/ksh/main.c
+++ b/bin/ksh/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.91 2018/04/09 17:53:36 tobias Exp $ */
+/* $OpenBSD: main.c,v 1.92 2018/05/18 13:25:20 benno Exp $ */
/*
* startup, main loop, environments and error handling
@@ -88,7 +88,6 @@ static const char *initcoms [] = {
"alias",
/* Standard ksh aliases */
"hash=alias -t", /* not "alias -t --": hash -r needs to work */
- "type=whence -v",
"stop=kill -STOP",
"autoload=typeset -fu",
"functions=typeset -f",
diff --git a/bin/ksh/sh.h b/bin/ksh/sh.h
index d665b5cd1c5..cf2c6c3a595 100644
--- a/bin/ksh/sh.h
+++ b/bin/ksh/sh.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sh.h,v 1.72 2018/04/09 17:53:36 tobias Exp $ */
+/* $OpenBSD: sh.h,v 1.73 2018/05/18 13:25:20 benno Exp $ */
/*
* Public Domain Bourne/Korn shell
@@ -382,6 +382,7 @@ int c_pwd(char **);
int c_print(char **);
int c_whence(char **);
int c_command(char **);
+int c_type(char **);
int c_typeset(char **);
int c_alias(char **);
int c_unalias(char **);