Attempting to set a user environment variable using input from a user in a bash script running in a makefile.
all:
if[ ! $(ENV_VAR) ] ; then \
read -p "What the variable?" env_var; \
if [[ $$env_var == valid_value || $$env_var == other_valid_value ]]; then \
echo export ENV_VAR=$$env_var >> /home/userName/.bashrc; \
source /home/userName/.bashrc \
else \
echo $$env_var is an invalid value\; Try again; \
fi \
fi
This code doesn't work. Is there any way to run source in a bash script?
Here's an example of the output:
What the variable? valid_value
What the variable? valid_value
What the variable? valid_value
...
After running the script the ~/.bashrc file did get the appropriate export command. Running source after the script does make and environment variable I need. I just need it to run in the make script.