LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-27-2006, 02:40 AM   #1
lewislu
LQ Newbie
 
Registered: Nov 2006
Posts: 1

Rep: Reputation: 0
export command not work in shell script?


Hello ,everybody ,I'm a newbie of linux .I have this question:I write a shell(bash) script as follows:
/************************************************/
#!/bin/sh

SKYEYE=/home/lewis/skyeye
export SKYEYE

/***********************************************/
save the file as skyeye1
in command line:
[lewis@localhost ]$chmod +x skyeye1
[lewis@localhost ]$./skyeye1
[lewis@localhost ]$echo $SKYEYE

[lewis@localhost ]$

I got nothing ,but according the book shoud get
/home/lewis/skyeye
What's wrong?
 
Old 11-27-2006, 04:08 AM   #2
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware 14.1 (32 and 64 bit)
Posts: 1,594

Rep: Reputation: 124Reputation: 124
I think that if you call a script it is executed in its own subshell that doesn't give variables and such stuff to the shell you called it from. You can set it in another way by sourcing the script, there are probably other ways I don't know about

Code:
. skyeye1 # dot space at the beginning of line
echo $SKYEYE
 
Old 11-27-2006, 04:24 AM   #3
olaola
Member
 
Registered: Aug 2006
Location: Italy
Distribution: Fedora
Posts: 41

Rep: Reputation: 15
when you run your skyeye1 script, exported variables are setted only in child shell sessions, not in tehe current one

olaola
 
Old 11-27-2006, 07:57 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Indeed. When any program is launched, including your script, it gets a copy of the environment of the "parent process" (=running program). The program in question can then change it's own environment any way it likes, but the changes will not affect the parent. When you use "export", like in your script, the changed environment variable will however be carried on to the children of your script (=the programs & scripts that are called in your script).
So, in short, when your script ends, it's environment settings are cleaned up and the changes you tried to make are thus lost.

Sourcing can indeed be a solution. "Sourcing", either via
. your_script.sh
or
source your_script.sh
actually takes the code of your_script.sh and runs it in the current environment, rather than creating a new environment.
 
Old 12-13-2013, 09:15 AM   #5
Konstantinos
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Rep: Reputation: Disabled
export a library path in a shell script does not work

Good Afternoon,

I thought that it would be better to continue this thread rather than creating a new one so, I am trying to set the library path as my program needs the MKL library routines. although this has worked in another system, in the current one it gives me an error and it is not very obvious why

the script is as follows:

export MKLPATH=/share/apps/intel/ictce/3.2.1.015/mkl/lib/em64t
export MKLINCLUDE=/share/apps/intel/ictce/3.2.1.015/mkl/include
#
ifort -O3 -static-intel -r8 -L$MKLPATH -I$MKLINCLUDE -lmkl_core -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 main.f int2str.f mmsup.f svsup.f sssup.f gengrid.f -o sequence.exe

the script runs succesfully and it compiles the program, but when i run the executable i get the following error:

./sequence.exe: error while loading shared libraries: libmkl_core.so: cannot open shared object file: No such file or directory

the library path is correct and the libraries do exist so it is strange why this happens.
 
Old 12-13-2013, 03:32 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,661

Rep: Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256
You need the "LD_LIBRARY_PATH" environment variable to be set to point to the nonstandard location.

OR you can edit the /etc/ld.so.conf file to add another path to the list of trusted paths for shared libraries.
 
Old 12-16-2013, 12:39 PM   #7
Konstantinos
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Rep: Reputation: Disabled
different issue

thank you for your reply, finally i did set the path to point to the non standard location, but i realised that this was not the issue.
the program compiled properly but i kept getting the segmentation fault error 174, in a discussion with the system supervisor, he told me that gfortran and intel libraries are getting mixed up for some reason and although i use ifort and have the proper paths pointed when it runs it switches and searches for gfortran standard libraries for some reason, this is not an issue of the paths anymore. something is getting mixed up and the declaration e.g. real*8:: A(length) has to be written as real*8,dimension(length):: A so i do not get the error( f90 f77 difference or something like that). eventually when it reaches the e.g. dpotri routine it gives me again the 174 error and i cannot do anything about it as it is a routine i use from the library and it should be working but it does not. the same program in another system compiles and runs properly. probably something is not set properly in the system. thank you for your reply

Konstantinos
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
my database export shell script run from command line but not form crontab saifee Linux - General 11 01-29-2012 09:24 AM
Perl shell-out to script dunna work. Works on command line. Why? jlangelier Linux - Software 1 08-28-2004 02:00 AM
No effect when 'export' command executed in a script? sylvain_gnu Linux - Software 6 04-20-2004 07:15 PM
'export' from a script doesn't work, why? sylvain_gnu Debian 3 04-20-2004 12:42 PM
Export command doesnt work correctly basix Linux - Software 6 02-28-2004 10:54 AM


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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration