I want to set 2 temp env vars and then run a binary.
The command is like this:
ENV_1=firstparam ENV_2=secondparam my_binary
I want to move the 2 env var assignment in a bash script and use a command like this:
setparams.sh my_binary
setparams.sh
#!/bin/bash
ENV_1=firstparam
ENV_2=secondparam
What's wrong here? Why do the vars are not being set?
By default all user defined variables are local. They are not exported to new processes. Use export command to export variables and functions
export ENV_1=firstparam
export ENV_2=secondparam
Also, instead of executing you should call source (built-in command that executes the content of the file passed as argument, in the current shell):
source setparams.sh && my_binary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With