atish0
November 18, 2010, 4:06pm
1
OS SCO Open Server 6.0 MP4
I am trying to change the value of a enviornment variable thru a script and want to pass a parameter on the commande line, If I hard code the value inside the script the script changes the enviornment variable
. mytest
where my test is
MYVAR=$1
export MYVAR
I am un able to pass parameters as follows
. mytest myparameter
Please guide
Thanks
atish0
November 18, 2010, 4:38pm
3
$1 is passed at the command line
. mytest parameter
The parameter will become $1 as my understanding
---------- Post updated at 04:38 PM ---------- Previous update was at 04:36 PM ----------
My need is to change the enviornment variable and for that I am using the dot script method so that the current enviornment is changed and available after the script exits
ctsgnb
November 18, 2010, 4:42pm
4
run it this way :
. ./mytest parameter
[ctsgnb@shell ~]$ env | grep MYVAR
[ctsgnb@shell ~]$ cat mytest
MYVAR=$1
export MYVAR
[ctsgnb@shell ~]$ . ./mytest myparam
[ctsgnb@shell ~]$ env | grep MYVAR
MYVAR=myparam
[ctsgnb@shell ~]$
or can alternatly enter the full path of mytest :
. /full/path/mytest myparameter
atish0
November 18, 2010, 5:27pm
5
without the dot command the vaules of environemnt are not changed. the script creates a sub shell and that is not available back to the parent shell.
I have tried the way you are mentioning.
---------- Post updated at 05:10 PM ---------- Previous update was at 04:44 PM ----------
Does not Work
. mytest hp4345 Command line
here is the code for mytest
#!/bin/sh
DFPRINTER=$1;export DFPRINTER;
after executing the above the enviornment variable is still same with old value.
this works
. mytest
code#!/bin/sh
DFPRINTER=hp4341;export DFPRINTER;
after executing the above the environment variable DFPRINTER value changes to hp4345
and I want to parametrize the hp4345 part so that I can pass on any desired value
---------- Post updated at 05:27 PM ---------- Previous update was at 05:10 PM ----------
. ./mytest parameter
the parameter is no being passed in to the script
If mytest contains
#!/bin/sh
DFPRINTER=$1;export DFPRINTER;
where /bin/sh is either the Bourne, Bash or Korn shell and
. ./mytest hp4345
does not set the environmental variable DFPRINTER to hp4345, then something else is going on.
Please confirm what shell you are using.
jgt
November 18, 2010, 8:56pm
7
Put it in your .profile, or in the script that uses it.