From 7c6cf2cdab5ada1736defe1a799b39d84a0e3d9b Mon Sep 17 00:00:00 2001 From: cecinestpasunepipe <110607403+cecinestpasunepipe@users.noreply.github.com> Date: Mon, 12 Dec 2022 14:47:53 +0100 Subject: [PATCH] Improve handing of dollar sign in Target Shell (#101) (DIS-1697) --- dissect/target/tools/shell.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dissect/target/tools/shell.py b/dissect/target/tools/shell.py index dc90d403f..4f06d0042 100644 --- a/dissect/target/tools/shell.py +++ b/dissect/target/tools/shell.py @@ -46,7 +46,7 @@ # remove `-` as an autocomplete delimeter on Linux # https://stackoverflow.com/questions/27288340/python-cmd-on-linux-does-not-autocomplete-special-characters-or-symbols - readline.set_completer_delims(readline.get_completer_delims().replace("-", "")) + readline.set_completer_delims(readline.get_completer_delims().replace("-", "").replace("$", "")) except ImportError: # Readline is not available on Windows log.warning("Readline module is not available") @@ -146,9 +146,12 @@ def _exec(self, func, command_args_str): Command execution helper that chains initial command and piped subprocesses (if any) together """ - argparts = ( - [] if command_args_str is None else list(shlex.shlex(command_args_str, posix=True, punctuation_chars=True)) - ) + + argparts = [] + if command_args_str is not None: + lexer = shlex.shlex(command_args_str, posix=True, punctuation_chars=True) + lexer.wordchars += "$" + argparts = list(lexer) try: if "|" in argparts: