LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-07-2011, 03:08 AM   #1
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Rep: Reputation: 135Reputation: 135
script not exporting variables


I have sles 10 . A user has a default shell of tcsh. I want to run a script which has to use ksh . In that script only some variables are exported, which will be used in subsequent scripts which are called inside it.

But the variables are not exported.

I am unable to find whether its a conflict of shell or what ??

I tried with debug mode, it only displays the command but not execute anyone ..
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 06-07-2011, 03:36 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Is this simply a case of the script being executed instead of sourced? If not, could you reproduce the problem with a minimal version of your script(s) and post here?

Cheers,

Evo2.
 
1 members found this post helpful.
Old 06-07-2011, 04:10 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by evo2 View Post
Is this simply a case of the script being executed instead of sourced? If not, could you reproduce the problem with a minimal version of your script(s) and post here?

Cheers,

Evo2.
It contains only some variables exported as:


PHP Code:
#!/bin/ksh

. /user/tmmltst/.profile
export LOCAL
=PLMDTST
export DB_VENDOR
=ORA
export MTI_ROOT
=/user/omfprod
##export LM_LICENSE_FILE=/user/omfprod/install/licenses.mti
export LM_LICENSE_FILE=8575@plmpox01
export ORACLE_HOME
=/user/oraclnt/OracleHomeClnt
export LD_LIBRARYN32_PATH
=$MTI_ROOT/bin:/user/oraclnt/OracleHomeClnt/lib32:/user/omfprod/lib32:$LD_LIBRARYN32_PATH
export ORACLE_SID
=PLMDTST
export TWO_TASK
=PLMDTST
export JAVA_HOME
=/usr/java/jre1.6.0_14
export PATH
=/usr/java/jre1.6.0_14/bin:$ORACLE_HOME/bin:$PATH
umask 002
;

#export Project_List="3790 3990 3750 3770"

export Project_List="3790 3990 3750 3770"

export sqluser="tmmltsdb/oracle"
export TC_USER="tmmltst"
export TC_PASS="tmmltst"

. /user/tmmltst/cusdir/Pdf/ALL_CATIA_PLM_PDF.sh 
 
Old 06-07-2011, 10:49 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
What are you doing/seeing that leads to the conclusion "the variables are not exported"?
 
2 members found this post helpful.
Old 06-07-2011, 11:56 PM   #5
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by catkin View Post
What are you doing/seeing that leads to the conclusion "the variables are not exported"?
Beacuse echo $VARIABLE doesnot return any values..
 
Old 06-08-2011, 12:17 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
If I understand correctly a tcsh user runs the ksh shell script (first lines illustrated in the OP) which goes on to run other scripts (calling method and language not known; depth of calls not known) which at some depth echo $VARIABLE does not work ...

It might help to know the missing details.
 
2 members found this post helpful.
Old 06-08-2011, 12:27 AM   #7
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by catkin View Post
If I understand correctly a tcsh user runs the ksh shell script (first lines illustrated in the OP) which goes on to run other scripts (calling method and language not known; depth of calls not known) which at some depth echo $VARIABLE does not work ...

It might help to know the missing details.
I commented the line calling other scripts, and the same result.
 
Old 06-08-2011, 12:36 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Please confirm at what point are you performing the echo?

I will reiterate what catkin has said but with an example:

Primary script (prim.sh):
Code:
#!/bin/ksh

. /user/tmmltst/.profile
export LOCAL=PLMDTST

/user/tmmltst/second.sh
Secondary script (second.sh):
Code:
#!/bin/ksh

echo $LOCAL
Then you run the script like:
Code:
./prim.sh
Is this the correct version of events (although simplified)?
 
2 members found this post helpful.
Old 06-08-2011, 01:12 AM   #9
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by grail View Post
Please confirm at what point are you performing the echo?

I will reiterate what catkin has said but with an example:

Primary script (prim.sh):
Code:
#!/bin/ksh

. /user/tmmltst/.profile
export LOCAL=PLMDTST

/user/tmmltst/second.sh
Secondary script (second.sh):
Code:
#!/bin/ksh

echo $LOCAL
Then you run the script like:
Code:
./prim.sh
Is this the correct version of events (although simplified)?
No actually I do echo outside the script in the shell, after executing the script ..
 
Old 06-08-2011, 01:27 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Then this would be your problem ... the moment the script finishes executing all variables will be lost.
 
1 members found this post helpful.
Old 06-08-2011, 01:37 AM   #11
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by grail View Post
Then this would be your problem ... the moment the script finishes executing all variables will be lost.
No, but if I am running with pure ksh or pure sh shells, then it's not loosing values outside of the script.
 
Old 06-08-2011, 02:15 AM   #12
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
If the default shell is /bin/tcsh, the ksh script cannot be sourced because in that case the sha-bang will be treated as a comment and ignored and the export statements will return a command not found error. Your only option is to change the ksh script to the C-shell equivalent, using setenv in place of export and again by sourcing it instead of executing.
 
1 members found this post helpful.
Old 06-08-2011, 02:20 AM   #13
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by divyashree View Post
No actually I do echo outside the script in the shell, after executing the script ..
Ahh, so my initial suspicion was correct.

Evo2.
 
1 members found this post helpful.
Old 06-08-2011, 03:09 AM   #14
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by colucix View Post
If the default shell is /bin/tcsh, the ksh script cannot be sourced because in that case the sha-bang will be treated as a comment and ignored and the export statements will return a command not found error. Your only option is to change the ksh script to the C-shell equivalent, using setenv in place of export and again by sourcing it instead of executing.
If the values will not inherit, how they will be passed to the scripts called inside the main one ?
 
Old 06-08-2011, 03:29 AM   #15
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
These two statements are in sharp contrast to each other:
Quote:
Originally Posted by divyashree View Post
No actually I do echo outside the script in the shell, after executing the script ..
Quote:
Originally Posted by divyashree View Post
If the values will not inherit, how they will be passed to the scripts called inside the main one ?
It's still not clear what is the sequence of events. Your first statement means you launch a script containing the export statements and then try to echo them after the script has terminated. In that case you will not see the changes since the parent shell does not inherit the child's environment. The second statement means you have a script which calls other scripts inside it: in this case the exported variables should be visible from the childs.

Here is a working example using a /bin/ksh script from a /bin/tcsh default shell:
Code:
$ cat > script.sh
#!/bin/ksh
export LOCAL=PLMDTST
export DB_VENDOR=ORA
export MTI_ROOT=/user/omfprod
./script_child.sh
$ chmod +x script.sh
$ cat > script_child.sh 
#!/bin/ksh
echo "The LOCAL variable is:     $LOCAL"
echo "The DB_VENDOR variable is: $DB_VENDOR "
echo "The MTI_ROOT variable is:  $MTI_ROOT"
$ chmod +x script_child.sh
$ ./script.sh
The LOCAL variable is:     PLMDTST
The DB_VENDOR variable is: ORA
The MTI_ROOT variable is:  /user/omfprod
Can you reproduce this behavior on your machine? Does it works exactly as in my example?
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script and exporting variables into a subshell spork Programming 3 10-14-2008 11:38 PM
exporting variables gecoool Programming 2 10-25-2005 01:17 AM
Using Bash Script for Exporting and Returning Environmental Variables Jicksta Programming 3 12-04-2004 04:14 PM
exporting variables in Perl nbp Programming 1 11-18-2003 08:35 AM
exporting global variables neo77777 Programming 6 09-18-2002 01:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration