Skip to content

Instantly share code, notes, and snippets.

@sjohnr
Last active July 16, 2021 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjohnr/60a3d567afeda7f83087e0ecbf41cefc to your computer and use it in GitHub Desktop.
Save sjohnr/60a3d567afeda7f83087e0ecbf41cefc to your computer and use it in GitHub Desktop.
Export output of piped command to an environment variable
function exp() {
export $1=$(cat /dev/stdin)
}

Description

This function exports what is piped to it (in stdin) as an environment variable.

Installation

Add this function to your .zshrc, .bashrc, etc.

Usage

Use this function at the end of a command, as in:

http -a my-client:secret -f POST :9000/oauth2/token grant_type=client_credentials scope=message.read | jq -r .access_token | exp ACCESS_TOKEN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment