Skip to content

Commit fecd771

Browse files
committed
More robust way of echoing $PATH
When we start a login shell to find the natural value of $PATH, instead of executing `env` in that shell then grepping for $PATH, we simply `printf` the $PATH directly. This should be more robust (by virtue printing the value directly rather than indirectly with env and then using a grep search for the answer.)
1 parent b7894fc commit fecd771

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

FixPath.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88

99

1010
def getSysPath():
11-
command = "/usr/bin/login -fpql $USER $SHELL -l -c \"env | grep '^PATH='\""
11+
command = "/usr/bin/login -fqpl $USER $SHELL -l -c 'printf \"%s\" \"$PATH\"'"
1212

1313
# Execute command with original environ. Otherwise, our changes to the PATH propogate down to
1414
# the shell we spawn, which re-adds the system path & returns it, leading to duplicate values.
1515
sysPath = Popen(command, stdout=PIPE, shell=True, env=originalEnv).stdout.read()
1616

1717
# Decode the byte array into a string, remove trailing whitespace, remove trailing ':'
18-
return sysPath.decode("utf-8").rstrip().rstrip(':').lstrip('PATH=')
18+
return sysPath.decode("utf-8").strip().rstrip(':')
1919

2020

2121
def fixPath():
22-
environ['PATH'] = getSysPath()
22+
currSysPath = getSysPath()
23+
environ['PATH'] = currSysPath
2324

2425
for pathItem in fixPathSettings.get("additional_path_items", []):
2526
environ['PATH'] = pathItem + ':' + environ['PATH']

0 commit comments

Comments
 (0)