Date: Thu, 05 Oct 2023 17:00:07 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 274280] Incompatible default shell configuration Message-ID: <bug-274280-227@https.bugs.freebsd.org/bugzilla/>
next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D274280 Bug ID: 274280 Summary: Incompatible default shell configuration Product: Base System Version: Unspecified Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: conf Assignee: bugs@FreeBSD.org Reporter: tg@mirbsd.org I=E2=80=99m upstream for mksh (shells/mksh in ports), and I=E2=80=99ve had = a user report problems on FreeBSD, which I was able to track down. dot.shrc=C2=B9 contains commands specific to FreeBSD sh which are not POSIX conformant nor compatible with mksh; specifically, the bind commands in lin= es 34ff, although the PS1 is also n=C5=8Dn-standard. The problem is exacerbated by dot.profile=C2=B2 exporting ENV, which makes = mksh look at .shrc in the first place, which it normally would not. Just like PS1, exporting ENV is something that should not be done. For ENV however, there=E2=80=99s the option of writing the designated file in a way= that is compatible with all shells that read it (which is not an option for PS1). My preference would be for FreeBSD to not export ENV. I understand this is = most likely too much; therefore, please add the following lines=E2=80=A6 if test -n "$KSH_VERSION"; then test -e ~/.mkshrc || return 0 . ~/.mkshrc return fi =E2=80=A6 between the comment end on line 8 and the comment beginning on li= ne 11 to fix this problem and MFC that to the active stable branches. The change will defer from .shrc to .mkshrc if it exists (and if so, return= its exit status up the chain), and just return true if it doesn=E2=80=99t exist. The change will make it so that, when mksh (or pdksh, oksh or AT&T ksh93, incidentally, but the stock dot.mkshrc has a whitelist for mksh/lksh and ju= st returns true for all other shells) is run, the remainder of the FreeBSD .sh= rc is ignored and the mksh one is used instead. It might be useful to defer to different files, depending on what shells are ported however this will raise complexity. Looking at your ports tree, I=E2=80=99m surprised to see that 1999 pdksh is= even still present. But that can be mostly lumped together with oksh. A more complete solution would thus be: if test -n "${KSH_VERSION:-}"; then # mksh/lksh? (shells/mksh port) case $KSH_VERSION in *LEGACY\ KSH*|*MIRBSD\ KSH*) test -e ~/.mkshrc || return 0 . ~/.mkshrc return ;; esac # AT&T ksh93? (shells/ast-ksh, shells/ksh, shells/ksh93) if (eval 'x=3D${.sh.version}') >/dev/null 2>&1; then test -e ~/.ksh93rc || return 0 . ~/.ksh93rc return fi # other pdksh variants (shells/oksh, shells/pdksh) test -e ~/.kshrc || return 0 . ~/.kshrc return fi This is assuming users of these shells would create the corresponding dotfi= les. There=E2=80=99s historic evidence for ~/.kshrc, mostly by pdksh/oksh users;= there=E2=80=99s none for ~/.ksh93rc TTBOMK (some, but few, seem to be using ~/.kshrc). This leaves out GNU bash, AT&T ksh88, yash, zsh (if any of these honour $EN= V). >From my shell detection utility=C2=B3, they can easily be detected by: if test -n "${BASH_VERSION:-}"; then =E2=80=A6 fi case ${YASH_VERSION:-} in *.*) =E2=80=A6 ;; esac case ${ZSH_VERSION:-} in *[0-9]*) =E2=80=A6 ;; esac case ${VERSION:-} in zsh*) =E2=80=A6 ;; esac (the last one is for old versions of zsh and may not be necessary any more) This leaves out AT&T ksh88, which is sensible as it=E2=80=99s binary-only a= nd only present on old Unic=C4=93s, and other sh variants like NetBSD sh, ash/dash,= etc. There *is* a dash port; dash does not support bind, and it does not set a s= hell parameter to detect it; dash does read $ENV. You=E2=80=99ll have broken das= h users, but that=E2=80=99s probably not a big issue. Unfortunately, FreeBSD /bin/sh doesn=E2=80=99t appear (I don=E2=80=99t have= access to a FreeBSD system at the moment, only a MidnightBSD system, but it seems to share /bin= /sh still) to set a variable to discern it either, so let=E2=80=99s just ignore= dash for now. Note: I don=E2=80=99t advocate for leaving out the bind commands from .shrc= instead. Users of the other shells *will* want to be able to read their shells=E2=80= =99 own startup files (especially considering mksh ships such a rich one predefined= ), so diverting to them is necessary. =E2=91=A0 https://cgit.freebsd.org/src/tree/usr.bin/man/man.sh =E2=91=A1 https://cgit.freebsd.org/src/tree/share/skel/dot.profile =E2=91=A2 http://www.mirbsd.org/cvs.cgi/contrib/code/Snippets/getshver?rev= =3DHEAD --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-274280-227>