don't set $_ if we're non-interactive.
-/* $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
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);
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();
-/* $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
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.. */
{
-/* $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
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++)
-/* $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
{ "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 },
-/* $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
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 */
-/* $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
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);
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();
-/* $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
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.. */
{
-/* $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
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++)
-/* $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
{ "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 },
-/* $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
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 */