summaryrefslogtreecommitdiff
path: root/bin/ksh
diff options
context:
space:
mode:
authorJason Downs <downsj@cvs.openbsd.org>1997-01-02 09:34:11 +0000
committerJason Downs <downsj@cvs.openbsd.org>1997-01-02 09:34:11 +0000
commit0555228bc967253747ca2cf16ec3a10143710171 (patch)
treec9f6bfb4bd518409d0c7192c841aaa45e534f08c /bin/ksh
parent5ec8bf97eb61afe45e84d47458c3c9cbfa46fc51 (diff)
Add FSH (set -o sh), initialize it if we're /bin/sh, and add the first use:
don't set $_ if we're non-interactive.
Diffstat (limited to 'bin/ksh')
-rw-r--r--bin/ksh/exec.c11
-rw-r--r--bin/ksh/history.c5
-rw-r--r--bin/ksh/main.c7
-rw-r--r--bin/ksh/misc.c3
-rw-r--r--bin/ksh/sh.h3
5 files changed, 20 insertions, 9 deletions
diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c
index 15027419bef..079ccc93940 100644
--- a/bin/ksh/exec.c
+++ b/bin/ksh/exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec.c,v 1.5 1996/11/21 07:59:28 downsj Exp $ */
+/* $OpenBSD: exec.c,v 1.6 1997/01/02 09:33:56 downsj Exp $ */
/*
* execute command tree
@@ -457,13 +457,14 @@ comexec(t, tp, ap, flags)
int type_flags;
int keepasn_ok;
int fcflags = FC_BI|FC_FUNC|FC_PATH;
+ volatile int underscore = (!Flag(FSH) || Flag(FTALKING));
/* snag the last argument for $_ XXX not the same as at&t ksh,
* which only seems to set $_ after a newline (but not in
* functions/dot scripts, but in interactive and scipt) -
* perhaps save last arg here and set it in shell()?.
*/
- if (*(lastp = ap)) {
+ if (underscore && *(lastp = ap)) {
while (*++lastp)
;
setstr(typeset("_", LOCAL, 0, 0, 0), *--lastp);
@@ -698,8 +699,10 @@ comexec(t, tp, ap, flags)
break;
}
- /* set $_ to program's full path */
- setstr(typeset("_", LOCAL|EXPORT, 0, 0, 0), tp->val.s);
+ if (underscore) {
+ /* set $_ to program's full path */
+ setstr(typeset("_", LOCAL|EXPORT, 0, 0, 0), tp->val.s);
+ }
if (flags&XEXEC) {
j_exit();
diff --git a/bin/ksh/history.c b/bin/ksh/history.c
index 0ed6ee708f6..f29e7e7d281 100644
--- a/bin/ksh/history.c
+++ b/bin/ksh/history.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: history.c,v 1.2 1996/12/29 12:24:05 graichen Exp $ */
+/* $OpenBSD: history.c,v 1.3 1997/01/02 09:34:00 downsj Exp $ */
/*
* command history
@@ -242,7 +242,8 @@ c_fc(wp)
return 1;
}
- setstr(local("_", FALSE), tf->name);
+ if (!Flag(FSH) || Flag(FTALKING))
+ setstr(local("_", FALSE), tf->name);
/* XXX: source should not get trashed by this.. */
{
diff --git a/bin/ksh/main.c b/bin/ksh/main.c
index e8425e1fab8..a6bd9369df2 100644
--- a/bin/ksh/main.c
+++ b/bin/ksh/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.4 1996/11/21 07:59:33 downsj Exp $ */
+/* $OpenBSD: main.c,v 1.5 1997/01/02 09:34:03 downsj Exp $ */
/*
* startup, main loop, enviroments and error handling
@@ -197,6 +197,11 @@ main(argc, argv)
change_flag(FPOSIX, OF_SPECIAL, 1);
#endif /* POSIXLY_CORRECT */
+ /* Check to see if we're /bin/sh. */
+ if (!strcmp(&kshname[strlen(kshname) - 3], "/sh")
+ || !strcmp(kshname, "sh") || !strcmp(kshname, "-sh"))
+ Flag(FSH) = 1;
+
/* import enviroment */
if (environ != NULL)
for (wp = environ; *wp != NULL; wp++)
diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c
index 5108389f6bf..0d5fe74eb7b 100644
--- a/bin/ksh/misc.c
+++ b/bin/ksh/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.3 1996/12/22 02:57:49 tholo Exp $ */
+/* $OpenBSD: misc.c,v 1.4 1997/01/02 09:34:07 downsj Exp $ */
/*
* Miscellaneous functions
@@ -161,6 +161,7 @@ const struct option options[] = {
{ "posix", 0, OF_ANY }, /* non-standard */
{ "privileged", 'p', OF_ANY },
{ "restricted", 'r', OF_CMDLINE },
+ { "sh", 0, OF_ANY }, /* non-standard */
{ "stdin", 's', OF_CMDLINE }, /* pseudo non-standard */
{ "trackall", 'h', OF_ANY },
{ "verbose", 'v', OF_ANY },
diff --git a/bin/ksh/sh.h b/bin/ksh/sh.h
index 9ae4ffb190c..588abd2c18e 100644
--- a/bin/ksh/sh.h
+++ b/bin/ksh/sh.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sh.h,v 1.4 1996/12/18 18:28:37 niklas Exp $ */
+/* $OpenBSD: sh.h,v 1.5 1997/01/02 09:34:10 downsj Exp $ */
/*
* Public Domain Bourne/Korn shell
@@ -472,6 +472,7 @@ enum sh_flag {
FPOSIX, /* -o posix: be posixly correct */
FPRIVILEGED, /* -p: use suid_profile */
FRESTRICTED, /* -r: restricted shell */
+ FSH, /* -o sh: favor sh behavour */
FSTDIN, /* -s: (invocation) parse stdin */
FTRACKALL, /* -h: create tracked aliases for all commands */
FVERBOSE, /* -v: echo input */