From 1cc2f2d8e2a9d52db2af9d740ce7ea135f66a08f Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sat, 8 Feb 2020 21:19:25 +0100 Subject: [PATCH] Skip shell functions when parsing env `getEnvFromShell` function calls `env` command through shell to get all defined environment variable. However `env` also returns the shell function defined with their whole code written on multiple lines. Such shell function definitions were not properly handled by `getEnvFromShell` which led to the following kind of error messages (seen for instance when running a terminal package in Atom): bash: module: line 1: syntax error: unexpected end of file bash: error importing function definition for `BASH_FUNC_module' With this change `getEnvFromShell` now skips shell function definition to guarantee only environment variables are recorded and a sane `result` array is returned. Fixes #20389 Fixes #17369 Fixes #13451 Fixes blueimp/atom-open-terminal-here#27 Fixes blueimp/atom-open-terminal-here#18 Fixes bus-stop/Termination#101 Fixes bus-stop/terminus#24 Fixes platformio/platformio-atom-ide-terminal#120 Fixes platformio/platformio-atom-ide-terminal#293 Fixes AtomLinter/linter-pylint#243 Fixes AtomLinter/linter-flake8#643 Fixes AtomLinter/linter-flake8#165 Fixes AtomLinter/linter-flake8#422 Fixes AtomLinter/linter-puppet-lint#68 Fixes autocomplete-python/autocomplete-python#347 --- src/update-process-env.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/update-process-env.js b/src/update-process-env.js index f4dd15851..cc2e444c2 100644 --- a/src/update-process-env.js +++ b/src/update-process-env.js @@ -121,13 +121,22 @@ async function getEnvFromShell(env) { } let result = {}; + let skip = false; for (let line of stdout.split('\n')) { - if (line.includes('=')) { + // start of shell function definition: skip full definition + if (line.includes('=() {')) { + skip = true; + } + if (!skip && line.includes('=')) { let components = line.split('='); let key = components.shift(); let value = components.join('='); result[key] = value; } + // end of shell function definition + if (line === '}') { + skip = false; + } } return result; }