I'm trying to write an menu driven program to automate some functions which involve loging to multiple hosts. The hosts can differ for every use, so I thought I would use an config file to get the hostnames. Now I need to set those values in the config file to environment variable to access by the menu script to login and proceed with the functions.
I tried to execute the config file from the shell script, but the environment variables are dying after the menu script is exited. The question is how to set those environment variable in the terminal for the complete session even after exiting the script, because if the menu gets failed in the 2nd or 3rd step and when the user tries to execute the script again it is mandating the user to run the config file inorder to set the env variables which is a pain for the user.
If my understanding is right, the source command is used to use the external file for the menu script which it is being called. But my query is once I execute the config file the env variables should be set not only to the child process which is created but to the parent process where the menu script is executed.
please let me know if you couldn't catch my point.
Arun
Newly set env variables are not available for the parent shell. However, if you need, what you can do is:
> Use 'printenv' command and redirect the output to a file from your function.
> Run this file once you are back in the main menu either using . or source depending on your shell.
Even though I run while returning back to the main menu it doesn't help me because once the script exits the env variables would die, so there is no way I can set the env variable to the parent process ??