Skip to content

Commit 8a0d3cf

Browse files
authored
Merge pull request #337 from python-cmd2/shell_expansion
No longer expanding env vars since the shell will do that
2 parents 4c9e18c + 80da52f commit 8a0d3cf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cmd2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,11 +3072,13 @@ def do_shell(self, command):
30723072
Usage: shell <command> [arguments]"""
30733073

30743074
try:
3075-
tokens = shlex.split(command, posix=POSIX_SHLEX)
3075+
# Use non-POSIX parsing to keep the quotes around the tokens
3076+
tokens = shlex.split(command, posix=False)
30763077
except ValueError as err:
30773078
self.perror(err, traceback_war=False)
30783079
return
30793080

3081+
# Support expanding ~ in quoted paths
30803082
for index, _ in enumerate(tokens):
30813083
if len(tokens[index]) > 0:
30823084
# Check if the token is quoted. Since shlex.split() passed, there isn't
@@ -3085,7 +3087,6 @@ def do_shell(self, command):
30853087
if first_char in QUOTES:
30863088
tokens[index] = strip_quotes(tokens[index])
30873089

3088-
tokens[index] = os.path.expandvars(tokens[index])
30893090
tokens[index] = os.path.expanduser(tokens[index])
30903091

30913092
# Restore the quotes

0 commit comments

Comments
 (0)