close
Skip to content

Fix the bash compatibility mode #9

Closed

Description

@McDutchie

Does anyone care about ksh's bash compatibility mode?

It's not compiled in my default. The RELEASE file says it's incomplete and experimental.

bash is pretty ubiquitous. I think if people want to run bash scripts, they'll run bash.

Would anyone object to getting rid?

Activity

  1. posguy99 commented on Jun 14, 2020

    @posguy99
  2. McDutchie commented on Jun 14, 2020

    @McDutchie
    Author

    Are distributions enabling it?

    It would surprise me if there are any that do. It's easy to check: ksh sets a $BASH_VERSION variable if it's enabled and adds a shopt builtin.

    …Oh. Now it would surprise me even more, because I just found out it doesn't even compile:

    $ bin/package make CCFLAGS='-Os -DSHOPT_BASH=1'
    [...]
    /usr/local/src/ksh93/ksh/src/cmd/ksh93/sh/init.c:1397:14: warning: comparison of distinct pointer types ('Shell_t *' (aka 'struct Shell_s *') and 'Shinit_f' (aka 'void (*)(struct Shell_s *, int)')) [-Wcompare-distinct-pointer-types]
                            shp>userinit = userinit = bash_init;
                            ~~~^~~~~~~~~
    /usr/local/src/ksh93/ksh/src/cmd/ksh93/sh/init.c:1397:24: error: expression is not assignable
                            shp>userinit = userinit = bash_init;
                            ~~~~~~~~~~~~ ^
    1 warning and 1 error generated.
    

    …that's a straight-up typo: that should be shp->userinit. It's clear the Bell Labs folks didn't bother to give this the most rudimentary testing before releasing ksh 93u+.

    After fixing the typo, compiling ksh succeeds but linking it fails:

    [...]
    + cc -O -L. -L/usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib -o ksh pmain.o libshell.a /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libdll.a /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libast.a -liconv -liconv /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libast.a -liconv -liconv /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libcoshell.a /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libast.a -liconv -liconv /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libast.a -liconv -liconv /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libcmd.a -lutil /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libast.a -liconv -liconv -lutil /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libast.a -liconv -liconv /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libast.a -liconv -liconv /usr/local/src/ksh93/ksh/arch/darwin.i386-64/lib/libast.a -liconv
    Undefined symbols for architecture x86_64:
      "_e_bash_rc", referenced from:
          _sh_main in libshell.a(main.o)
      "_sh_bash1", referenced from:
          _infof in libshell.a(args.o)
      "_sh_bash2", referenced from:
          _infof in libshell.a(args.o)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    mamake [cmd/ksh93]: *** exit code 1 making ksh
    mamake: *** exit code 1 making cmd/ksh93
    mamake: *** exit code 1 making all
    
  3. DavidMorano commented on Jun 14, 2020

    @DavidMorano

    Does anyone care about ksh's bash compatibility mode?

    I am (possibly one of the people) continuing the development of ksh2020 and I have not bothered to even attempt to turn on the BASH compatibility mode, nor do I have any desire to do so. But I am interested in any other responses that people might make here.

  4. McDutchie commented on Jun 14, 2020

    @McDutchie
    Author
  5. DavidMorano commented on Jun 14, 2020

    @DavidMorano
  6. McDutchie commented on Jun 16, 2020

    @McDutchie
    Author
  7. DavidMorano commented on Jun 16, 2020

    @DavidMorano
  8. added
    TODOThings to be done before releasing
    and removed
    questionFurther information is requested
    on Jun 16, 2020
  9. changed the title [-]RFD: bash compatibility mode[/-] [+]Fix the bash compatibility mode[/+] on Jun 16, 2020
  10. McDutchie commented on Jun 16, 2020

    @McDutchie
    Author

    There has been an objection on the korn-shell list against removing the broken bash compatibility mode. Here is my reply.

    In short: It falls to the people interested in using this to fix it, or have it fixed. Either someone fixes this before we release, or it gets removed shortly before release.

    So, this is now a TODO item.

  11. JohnoKing commented on Jun 16, 2020

    @JohnoKing

    Well, FWIW it is probably worth the effort to fix the local builtin present in the Bash compatibility mode. This is quoted from @bk2204's comment in att#220:

    I'll point out a few things about the local keyword:

    1. There's a request to the Austin Group (the POSIX folks) about standardizing it as
      part of POSIX which has garnered a lot of comments in favor. ksh has typically
      been capable of running POSIX commands, so it may be worthwhile to implement
      for that reason.

    2. Debian requires all shells that can be used as /bin/sh to implement local (and
      they don't build with SHOPT_BASH). Consequently, it isn't possible to use ksh
      as /bin/sh on a Debian or Ubuntu system.

    3. Git requires a shell providing local in order to run the testsuite and shell
      commands. Consequently, it isn't possible to use ksh as the shell for Git.

    4. All other open source POSIX-compliant shells that I'm aware of implement
      local: bash, dash, mksh, pdksh (and derivatives, like OpenBSD's ksh),
      and zsh.

    The first point seems to be referencing this request on the Austin Group Defect Tracker. The other points are all perfectly valid reasons to have a local builtin, although this project does have a 'bug fixes only' policy, as in the ksh93u+m README:

    1. No new features; bug fixes only (but see items 3 and 4). Feature development is for a future separate branch.

    The feature development branch hasn't been created yet, so improvements to the local builtin will have to be placed behind the SHOPT_BASH ifdef with the rest of the Bash compatibility code, as the local builtin isn't enabled by default.

  12. McDutchie commented on Jun 16, 2020

    @McDutchie
    Author

    Well, I am not a policy absolutist. I think policies should be broken if there are solid reasons why following them is worse than not following them.

    Adding a local builtin just might be such a case, precisely because POSIX is likely to mandate one, one of these years. POSIX compliance was one of Korn's stated core objectives, and is one of ours.

    However, to be anything like compatible with other shells, local should implement dynamic scoping, not static scoping like typeset. See Part III, Q28 in this FAQ, to know the difference.

    In standard ksh mode, local should then only work in POSIX functions (defined like this() { ...; }), and it should implement dynamic scoping. The behaviour of typeset would be unchanged.

    In bash compatibility mode (if it gets fixed), local should simply be a synonym of typeset without options, and both should implement dynamic scoping, even in ksh functions defined with the function keyword – because that is how typeset a.k.a. declare behaves in bash, mksh, yash, and zsh. Which means ksh static scoping would not be available if ksh is compiled in bash compatibility mode, but that is the price. You can't have both in one typeset. (edit: unless we add a new shell option for that instead…)

  13. 10 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    TODOThings to be done before releasingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions