Module shell_source.source
Functions
def source(script: Union[str, pathlib.Path], shell: str = 'sh', *, variables: Collection[str] = (), ignore_locals: bool = False, shell_config: ShellConfig = ShellConfig(source_cmd='source {script}', exit_cmd='exit {code}', redirect_stdout='{cmd} >> {file}', boolean_or='{cmd1} || {cmd2}', get_var='${var}', get_all_locals='set', prev_exit_code='$?'), **subprocess_kwargs) ‑> Dict[str, str]
-
Run a shell script and return its variables as a dictionary.
NOTE: If the script defines variables with newlines in their values it is undefined behaviour, though it will not raise an exception.
Args
script
- The shell script to source. It may contain arguments, file redirections, etc so long as it is supported by the shell you give.
shell
- The shell to use. If the shell you give is in the path it's name suffices, otherwise give the path to it. You may also pass flags, such as -x or -e. Default is "sh".
variables
- The names of the variables set in the script to return. By default, all variables are returned.
ignore_locals
- If True, no local variables set by the script are returned. Default is False.
shell_config
- An instance of ShellConfig that specifies how to interact with the given shell. If your shell is (somewhat) posix-compliant the default should work.
subprocess_kwargs
- Any other keyword arguments are passed to subprocess.run. By default, check=True is passed. Also, args, input and text are not allowed.