Wednesday, October 31, 2018

Re: Why&how do "sh" and "ksh" differ in behavior e.g. PS1 presentation, while their binaries are equal?

On Tuesday, October 30, 2018 4:33 PM, Sebastien Marie <semarie@online.fr> wrote:
> On Tue, Oct 30, 2018 at 08:11:24AM +0000, Joseph Mayer wrote:
>
> > On a quick sourcecode check I didn't see any code paths e.g.
> > "if (argv[0] matches "ksh") { something } else { something else }"
> > however I presume I missed something.
>
> yes, the check was too quick, it seems :)
>
> src/bin/ksh/main.c
> 134 int
> 135 main(int argc, char *argv[])
> 136 {
> 137 int i;
> 138 int argi;
> 139 Source *s;
> 140 struct block *l;
> 141 int restricted, errexit;
> 142 char *wp;
> 143 struct env env;
> 144 pid_t ppid;
> 145
> 146 kshname = argv[0];
> 147
> ...
> 236 / Check to see if we're /bin/sh. */237 if (!strcmp(kshname, "sh") || !strcmp(kshname, "-sh") ||
> 238 (strlen(kshname) >= 3 &&
>
> 239 !strcmp(&kshname[strlen(kshname) - 3], "/sh"))) {
> 240 Flag(FSH) = 1;
> 241 version_param = "SH_VERSION";
> 242 }
> 243
>
> ---------------------------------------------------------------------------------------------------------------------
>
> Sebastien Marie

Hi Sebastien,

Thanks a lot for clarifying.

sh's man page (http://man.openbsd.org/sh#DESCRIPTION) says:

"This version of sh is actually ksh in disguise. As such, it also
supports the features described in ksh(1). This manual page describes
only the parts relevant to a POSIX compliant sh."

When I read that originally, I perceived it as that "sh" and "ksh"
normally would have equivalent behavior - which also seems logical
given that their binaries are byte-equivalent.

The meaning I gather from the sentence is that sh and ksh are
equivalent and that instead the man pages will describe different
functionalities that are actually available in both.

Can that phrase in sh's man page be tweaked so that my misunderstanding
no longer is possible?

Do you find my misunderstanding a reasonable reading?

Joseph

No comments:

Post a Comment