I have a shell script I want to run that will set environment variables based on the value of an input variable submitted when the shell script is called. For example:
$ mgenv.sh prod
This would set environment variables for prod
$ mgenv.sh test
This would set environment variables for test
When I run the script using the syntax above, it works fine. However, my environment variables are not being set. Example of the syntax used in the shell script:
FIN_INTERFACE_DIR=\u06\interfaces\$1;export FIN_INTERFACE_DIR
Like I said, the script runs to completion, no errors reported - and then I check my environment variables and FIN_INTERFACE_DIR is not set.
If I take the input variable of the equation and hard code in my environment variables like so:
FIN_INTERFACE_DIR=\u06\interfaces\prod;export FIN_INTERFACE_DIR
Then run it with this command:
$ mgenv.sh
I get the same result - the script runs through clean without errors but no environment variables are set.
HOWEVER, my next test was to use the hardcoded variable but run the script with the following command:
$ . ./mgenv.sh
This worked great! Environment variable was set and exported. Finally - I use the new command and re-institute the use of the run-time variable $1 and run the following command:
$ . ./mgenv.sh prod
At this, I get the dreaded
1: parameter not set
So - how can I run this script with an input parameter and have it actually set environment variable? Any suggestions? Thanks.