diff --git a/sh_expand/bash_expand.py b/sh_expand/bash_expand.py index b849a95..7fd47af 100644 --- a/sh_expand/bash_expand.py +++ b/sh_expand/bash_expand.py @@ -4,7 +4,6 @@ import sys import tempfile from collections.abc import Callable -from contextlib import contextmanager from typing import TextIO import pexpect @@ -227,14 +226,6 @@ def close(self): # TODO: Fails sometimes pass - @contextmanager - def subshell(self): - try: - self.run_command(STR_COMMAND) - yield - finally: - self.run_command("exit") - def expand_word(self, word: str) -> list[str]: assert self.is_open self.log("To expand with bash:", word) @@ -335,9 +326,7 @@ def compile_node(ast_object: AstNode, exp_state: BashExpansionState) -> AstNode: def compile_node_pipe(ast_node: PipeNode, exp_state: BashExpansionState): - # TODO: Handle shopt -s lastpipe - with exp_state.subshell(): - ast_node.items = [compile_node(item, exp_state) for item in ast_node.items] + ast_node.items = [compile_node(item, exp_state) for item in ast_node.items] return ast_node @@ -355,8 +344,7 @@ def compile_node_command(ast_node: CommandNode, exp_state: BashExpansionState): def compile_node_subshell(ast_node: SubshellNode, exp_state: BashExpansionState): - with exp_state.subshell(): - ast_node.body = compile_node(ast_node.body, exp_state) + ast_node.body = compile_node(ast_node.body, exp_state) return ast_node @@ -391,8 +379,7 @@ def compile_node_redir(ast_node: RedirNode, exp_state: BashExpansionState): def compile_node_background(ast_node: BackgroundNode, exp_state: BashExpansionState): ast_node.redir_list = compile_redirections(ast_node.redir_list, exp_state) - with exp_state.subshell(): - ast_node.node = compile_node(ast_node.node, exp_state) + ast_node.node = compile_node(ast_node.node, exp_state) return ast_node diff --git a/sh_expand/expand.py b/sh_expand/expand.py index 77c5cf9..30b8188 100644 --- a/sh_expand/expand.py +++ b/sh_expand/expand.py @@ -1,5 +1,3 @@ -import copy - from shasta.ast_node import * from sh_expand.util import log @@ -442,8 +440,7 @@ def expand_command(command, exp_state: ExpansionState): def expand_pipe(node, exp_state): for i, n in enumerate(node.items): - # copy environment to simulate subshell (no outer effect) - node.items[i] = expand_command(n, copy.deepcopy(exp_state)) + node.items[i] = expand_command(n, exp_state) return node @@ -477,21 +474,16 @@ def expand_and_or_semi(node, exp_state): return node def expand_redir_subshell(node, exp_state): - # copy environment to simulate subshell (no outer effect) - node.node = expand_command(node.node, copy.deepcopy(exp_state)) - + node.node = expand_command(node.node, exp_state) return node def expand_background(node, exp_state): - # copy environment to simulate subshell (no outer effect) - node.node = expand_command(node.node, copy.deepcopy(exp_state)) - + node.node = expand_command(node.node, exp_state) return node def expand_defun(node, exp_state): # TODO 2020-11-24 MMG invalidate postional args - node.body = expand_command(node.body, copy.deepcopy(exp_state)) - + node.body = expand_command(node.body, exp_state) return node def expand_for(node, exp_state):