Set/Export Env Vars from with Shell Script With Input Variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Set/Export Env Vars from with Shell Script With Input Variable
# 1  
Old 03-18-2010
Set/Export Env Vars from with Shell Script With Input Variable

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.
# 2  
Old 03-18-2010
Should work, for example:
Code:
$ myvar=
$ echo $myvar
$

Code:
$ cat setenv1
#!/bin/sh

export myvar=$1

Code:
$ . ./setenv1 "Hi there"
$ echo $myvar
Hi there
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH script to export var to env

Hi all I am trying to create a script that takes a password input then writes that to a tmp file and puts that tmp file path in my env as a var. It does everything but export the my env and I am unsure why. I am using Ubuntu 12.4 #!/bin/bash read -s -p "Enter Password: " gfpassword... (5 Replies)
Discussion started by: koikoi
5 Replies

2. Shell Programming and Scripting

List of Shell Env Vars

Hia, echo ${!S*} gives me all those env vars starting with S like SHELL SECONDS SHELLOPTS SHLVL etc. is there any way to deflate the shell variables' range like echo ${!A-E*} OR echo ${!A..S*} to list all env vars starting within range of A till E. Thanks Regards, Nasir (1 Reply)
Discussion started by: busyboy
1 Replies

3. Shell Programming and Scripting

how to set/get shell env variable in python script

greetings, i have a sh script that calls a python script. the sh script sets an env variable BIN: export BIN=bin64i need to get that BIN variable's value and use it within this python script. anyone know how to do this? thanx in advance. (5 Replies)
Discussion started by: crimso
5 Replies

4. Solaris

export vs env vs set commands

Hi I'm trying to understand variable scopes in solaris10. It is said that to display env variables we use 3 commands : - env - set - export What is the difference between them ? thx for help. ---------- Post updated at 11:00 AM ---------- Previous update was at 10:50 AM ---------- ... (2 Replies)
Discussion started by: presul
2 Replies

5. Shell Programming and Scripting

export and access env variable in two scripts

Hi, I have two scripts say one.sh and two.sh. I want one.sh to continuously export a variable in loop. and when two.sh starts then it should read the last value exported from one.sh. file: one.sh #! bin/sh for i in `seq 1 1 4000000`; do export VAR=$(($i**$i)) ; done file two.sh ... (2 Replies)
Discussion started by: bhushan123
2 Replies

6. UNIX for Advanced & Expert Users

How to export ENV variables, which remains set for all the shell

Hi ! How to export ENV variables, which remains set for all the shell Example :- Login :myID Pwd : **** -> Here my ID .profile is executed. Let say I set MYENV variable Kisses% rlogin ABC -l XXXGroupID -> I login into a remote Solaris Server ABC password : **** -> "XXXGroupID's... (1 Reply)
Discussion started by: dashok.83
1 Replies

7. Shell Programming and Scripting

Env vars in a SED script

Hello, <Preamble> I'm writing an installation script for use with PKGADD. What I want to do is take one of the variables set in the REQUEST script and use that in the install script so I can change applications configuration. My install script is as follows: sed ' /^DIRNAME/ i\... (8 Replies)
Discussion started by: Bags
8 Replies

8. AIX

Do I need to remote after installation of s/w and set the env variable

Hi, I have installed ODWEK software on AIX box and set the environment variables like: PATH,LIBPATH,LD_LIBRARY_PATH,CLASSPATH. My question here is do I need to reboot the system to take these changes or is there anyother workaround. I heard that there is 'export'. But I don't know how far it... (1 Reply)
Discussion started by: srangu
1 Replies

9. AIX

Do I need to reboot after installation of s/w and set the env variable

Hi, I have installed ODWEK software on AIX box and set the environment variables like: PATH,LIBPATH,LD_LIBRARY_PATH,CLASSPATH. My question here is do I need to reboot the system to take these changes or is there anyother workaround. I heard that there is 'export'. But I don't know how far it... (1 Reply)
Discussion started by: srangu
1 Replies

10. UNIX for Dummies Questions & Answers

Export command giving Variable Name vs the Value set for the Variable

I'm having an issue when I export within my program. I'm getting the variable name, not the variable value. I have a configuration file (config.txt) that has the values of the variables set as so: set -a export ARCHIVEPOSourceDir="/interfaces/po/log /interfaces/po/data" export... (2 Replies)
Discussion started by: ParNone
2 Replies
Login or Register to Ask a Question