Goals:
- One-liner script execution
- Changes environment variables in the caller
Is this possible?
I know you can do something like curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
, but this doesn’t allow changing environment variables in the calling environment.
Advertisement
Answer
You can use process substitution together with the .
(source) command:
. <(curl https://www.server.com/env.sh)
This would import all variable, alias and function definitions from env.sh
into the scope of the running shell. However, it would not implicitly export the variables to the environment. To achieve this export
has to be explicitly called in env.sh
or the calling shell. Like this:
export FOO="test"