Skip to content

Subshell isolation incomplete: functions, cd, traps, positional params leak #357

@chaliy

Description

@chaliy

Description

Subshells ( ... ) should provide full isolation — changes to functions, working directory, traps, and positional parameters should not leak to the parent shell. Currently, several of these leak.

Scope

  • Function definitions leak: Functions defined in ( f() {...}; f ) are visible after the subshell
  • cd leaks: ( cd /tmp ) changes the parent's working directory (VFS model issue)
  • Traps leak: ( trap 'echo child' EXIT ) affects the parent
  • Positional params leak: ( set -- x y ) modifies parent's $@

Repro

# Function isolation
( f() { echo inside; }; f )
f 2>/dev/null; echo $?
# bashkit outputs: inside\ninside\n0 (f leaks to parent)
# expected: inside\n127 (f not found in parent)

# Positional params
set -- a b c
( set -- x y; echo "$@" )
echo "$@"
# bashkit outputs: (empty)\n(empty) (params broken)
# expected: x y\na b c

Test coverage

4 skipped tests in crates/bashkit/tests/spec_cases/bash/subshell.test.sh (PR #351).

Oils reference: https://github.com/oilshell/oil/blob/master/spec/subshell.test.sh

Related

  • This is expected behavior in bashkit's stateless interpreter model — subshells are not true forks

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions