Skip to content

Broken PS1 prompt when using mksh #4824

@clipcarl

Description

@clipcarl

Is there an existing issue for this?

  • I have searched the existing issues

Midnight Commander version and build configuration

GNU Midnight Commander 4.8.33
Built with GLib 2.84.1
Built with S-Lang 2.3.3 with terminfo database
Built with libssh2 1.11.1
With builtin editor
With subshell support as default
With support for background operations
With mouse support on xterm and Linux console
With internationalization support
With multiple codepages support
With ext2fs attributes support
Virtual File Systems:
 cpiofs, tarfs, sfs, extfs, ftpfs, sftpfs, shell
Data types:
 char: 8; int: 32; long: 64; void *: 64; size_t: 64; off_t: 64; uintmax_t: 64;

Operating system

Linux clip 6.17.4-0-stable #1-Alpine SMP PREEMPT_DYNAMIC 2025-10-21 08:38:12 x86_64 GNU/Linux

Is this issue reproducible using the latest version of Midnight Commander?

  • I confirm the issue is still reproducible with the latest version of Midnight Commander

How to reproduce

  1. Set your shell to mksh
  2. Set PS1 variable. Fox example to: PS1='$PWD $ '
  3. Run Midnight Commander
  4. Observe the PS1 prompt displayed by the subshell

Expected behavior

The PS1 prompt displayed by the subshell should be displayed properly. Variable and command substitution should work as expected.

Actual behavior

The PS1 prompt displayed by the subshell is not displayed correctly. For the example I gave above (PS1='$PWD $ ') it literally displays the string '$PWD $ ' without properly substituting the variable. No variable or command substitutions work.

Additional context

Seems related to feature #4634. Opening this up as a separate bug as the behavior I'm describing is in fact a bug in the current behavior of Midnight Commander and not a desired new feature.

Midnight Commander seems to be doing a lot of unnecessary convoluted things with respect to the PS1 prompt under mksh. As a temporary workaround adding the following to my mkshrc after the point where PS1 is defined fixes things for now by preventing Midnight Commander from overwriting the PS1 variable and preventing it from using its own broken precmd() function (makes PS1 read-only):

# hack to fix Midnight Commander with mksh
if [ "$MC_SID" ]
then
    mc_fixed_precmd() { pwd >&9; kill -STOP $$; }
    PS1="\$(mc_fixed_precmd)$PS1"
    typeset -r PS1
fi

On my system file descriptor 9 always seems to be correct for the workaround but your mileage may vary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues not related to a specific subsystemprio: mediumHas the potential to affect progressver: 4.8.33Reproducible in version 4.8.33

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions