
Security News
Opengrep Adds Apex Support and New Rule Controls in Latest Updates
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
A python module for sourcing variables from shell scripts.
You can install this package with pip or conda.
$ pip install shell-source
$ conda install -c abrahammurciano shell-source
The full documentation is available here
This module provides a function source
which attempts to mimic the shell's source command.
The purpose of this function is to allow you to run a shell script which sets either environment variables or local variables, and then give you access to those variables. Normally this is not a straght-forward task, but this function achieves it by running the script in its intended shell then injecting commands to the shell to write its local variables and its environment variables to a temporary file. Finally it reads the temporary file and parses it to return to you with exactly the data you asked for.
If you just pass a script and an interpreter you'll get back all the environment variables and local variables visible to and set by the script.
>>> from shell_source import source
>>> variables = source("path/to/script.sh", "bash")
>>> # It returns a dictionary of local and environment variables known by the script.
>>> variables
{"USER": "abraham", "PATH": "/bin:/usr/bin", ..., "foo": "bar"}
If you specify the argument variables
, then only those variables you passed will be present as keys in the returned dictionary.
>>> source("path/to/script.sh", "zsh", variables=("foo", "bar", "biz"))
{"foo": ..., "bar": ..., "biz", ...}
If you don't want to obtain any local variables set by the script, but only want the environment variables, you can pass ignore_locals=True
.
If you want to pass arguments to the shell, for example -x
or -e
, you can pass it directly in the shell
argument.
>>> source("path/to/script.sh", "bash -x")
If you want to pass arguments to the script being sourced, you can pass them in the args
argument.
>>> source("path/to/script.sh", "bash", args=("foo", "bar"))
This module has been tested to work with bash
, zsh
, and ksh
out of the box. You can use any other shell that's somewhat posix compliant, but it it doesn't work, you may have to create a class derived from the Scripter
class to indicate to source
how to interact with the shell you want to use.
Some specialized implementations of Scripter
are provided in shell_source.scripters
for shells that are not posix compliant, such as csh
, tcsh
and fish
.
For example, to use tcsh
to source a script, you can use the CshScripter
class like so:
>>> source("path/to/script.csh", "tcsh", scripter=CshScripter())
FAQs
A python module for sourcing variables from shell scripts
We found that shell-source demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.