bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash ONESHOT optimization in conjunction with interactive mode breaks


From: Andrew Hamon
Subject: Bash ONESHOT optimization in conjunction with interactive mode breaks
Date: Sun, 4 Jun 2023 18:07:40 -0700

Configuration Information [Automatically generated, do not change]:

Machine: x86_64

OS: linux-gnu

Compiler: gcc

Compilation CFLAGS: -g -O2 -Wno-parentheses -Wno-format-security

uname output: Linux nas 5.15.85 #1-NixOS SMP Wed Dec 21 16:36:38 UTC
2022 x86_64 GNU/Linux

Machine Type: x86_64-pc-linux-gnu


Bash Version: 5.1

Patch Level: 16

Release Status: release


Description:

    When running a command in interactive mode (i.e. bash -ic '/some/command')
    a bash script will stop itself and put it in the background unexpectedly.

Repeat-By:

    Take the following script:


        #!/usr/bin/env bash

        # Run some command in an interactive shell
        $SHELL -ic '/usr/bin/env echo hello'

        export IN_SHELL_TEST=true

        # Launch a new $SHELL with modified environment
        $SHELL -i


    A typical session looks like this:


        $ ./shell-test
        hello

        [1]+  Stopped                 ./shell-test
        $ echo $IN_SHELL_TEST

        $ fg
        ./shell-test
        $ echo $IN_SHELL_TEST
        true


    This is very unexpected behavior. I would expect to launch
    directly into the new shell, rather than have it start
    in the background.

Fix:

    Alex Shpilkin discovered that disabling ONESHOT optimization
    prevents the bug from presenting. He did this by recompiling
    bash after removing '#define ONESHOT'.

    Another mitigation is to prefix the first command with `exec`,
    for example:

        $SHELL -ic 'exec /usr/bin/env echo hello'



reply via email to

[Prev in Thread] Current Thread [Next in Thread]