niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
how to use Env variables & its path in ksh shell script
Post new topic   Reply to topic Page 1 of 1 [9 Posts] View previous topic :: View next topic
Author Message
Jon LaBadie
*nix forums beginner


Joined: 06 May 2006
Posts: 46

PostPosted: Thu Jul 20, 2006 12:19 pm    Post subject: Re: how to use Env variables & its path in ksh shell script Reply with quote

dalu.gelu@gmail.com wrote:
Quote:
Typical answer is "can't be done", same as with "how can I put a
cd <some_directory> in a script and have it in effect after it finishes?"

but I guess there is some mechanism by which u can cd to a directory
by executing the script. but i don't know the way...

my original qu was I have a .ksh script file (let x.ksh) which inturn
when executed, it performs some set and unset env variables, let some
changes in PATH & LD_LIBRARY_PATH from the script itself, so that the
changes affect to the user evenif he logs next time.
how i can achieve this?


I already did say how to do this in the part of my message you snipped.

For setting things like PATH during login, put them in the user's
$HOME/.profile, or put a source of a global set of config statements
into their .profile.
Back to top
Bruce Barnett
*nix forums Guru


Joined: 21 Feb 2005
Posts: 324

PostPosted: Thu Jul 20, 2006 10:33 am    Post subject: Re: how to use Env variables & its path in ksh shell script Reply with quote

"Chris F.A. Johnson" <cfajohnson@gmail.com> writes:

Quote:
On 2006-07-20, dalu.gelu@gmail.com wrote:

Typical answer is "can't be done", same as with "how can I put a
cd <some_directory> in a script and have it in effect after it finishes?"

but I guess there is some mechanism by which u can cd to a directory
by executing the script. but i don't know the way...

You cannot do it by executing the file, which created a new
proicess; you can do it by sourcing the file.

Let me clarify Chris's statement.

Your shell is one process.
If you start up a new process, and change the current directory,
this does not change the directory of the current shell process.

So if you execute
./program
or
./program &

it may change it's directory, but it won't CHANGE your shell.
If it did, you would have chaos.

Therefore you have to give data to your current process, and change that.

One way to do it is to use an alias (or shell function).

A second is to source a file (using the "." command).

I like combining these two steps., by having an alias that sources a
file.


--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Thu Jul 20, 2006 7:55 am    Post subject: Re: how to use Env variables & its path in ksh shell script Reply with quote

On 2006-07-20, dalu.gelu@gmail.com wrote:
Quote:

Typical answer is "can't be done", same as with "how can I put a
cd <some_directory> in a script and have it in effect after it finishes?"

but I guess there is some mechanism by which u can cd to a directory
by executing the script. but i don't know the way...

You cannot do it by executing the file, which created a new
proicess; you can do it by sourcing the file.

Quote:
my original qu was I have a .ksh script file (let x.ksh) which inturn
when executed, it performs some set and unset env variables, let some
changes in PATH & LD_LIBRARY_PATH from the script itself, so that the
changes affect to the user evenif he logs next time.
how i can achieve this?

Source it in whatever initialization file ksh reads when you log in
($HOME/.profile?),


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
dalu.gelu@gmail.com
*nix forums beginner


Joined: 18 Jul 2006
Posts: 5

PostPosted: Thu Jul 20, 2006 7:14 am    Post subject: Re: how to use Env variables & its path in ksh shell script Reply with quote

Quote:
Typical answer is "can't be done", same as with "how can I put a
cd <some_directory> in a script and have it in effect after it finishes?"

but I guess there is some mechanism by which u can cd to a directory
by executing the script. but i don't know the way...

my original qu was I have a .ksh script file (let x.ksh) which inturn
when executed, it performs some set and unset env variables, let some
changes in PATH & LD_LIBRARY_PATH from the script itself, so that the
changes affect to the user evenif he logs next time.
how i can achieve this?
Back to top
Jon LaBadie
*nix forums beginner


Joined: 06 May 2006
Posts: 46

PostPosted: Wed Jul 19, 2006 2:53 pm    Post subject: Re: how to use Env variables & its path in ksh shell script Reply with quote

dalu.gelu@gmail.com wrote:
Quote:
thanks Ed. but I want to set and unset an env variable from my
script.How can I achieve that?


"from my script" sounds like you want to perform these actions
in a script and have them affect the shell that called the script.

Typical answer is "can't be done", same as with "how can I put a
cd <some_directory> in a script and have it in effect after it finishes?"

But for some special purposes you can "source" a simple script that
sets variables or changes directories. To do this, run the script
as ". script" (a period space) rather than "script". This causes
the current shell to read the script rather than a child shell.
Back to top
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Wed Jul 19, 2006 1:50 pm    Post subject: Re: how to use Env variables & its path in ksh shell script Reply with quote

dalu.gelu@gmail.com wrote:

Quote:
thanks Ed. but I want to set and unset an env variable from my
script.How can I achieve that?

$ var="value"

$ echo "$var"
value
$ unset var
$ echo "$var"

Regards,

Ed.
Back to top
dalu.gelu@gmail.com
*nix forums beginner


Joined: 18 Jul 2006
Posts: 5

PostPosted: Wed Jul 19, 2006 10:48 am    Post subject: Re: how to use Env variables & its path in ksh shell script Reply with quote

thanks Ed. but I want to set and unset an env variable from my
script.How can I achieve that?
Back to top
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Tue Jul 18, 2006 1:46 pm    Post subject: Re: how to use Env variables & its path in ksh shell script Reply with quote

dalu.gelu@gmail.com wrote:

Quote:
Hi
can anybody let me know how to use the env path & its variable in ksh
script.
Thanks in advance.


echo "$PATH"

If you want anything else, be more specific.

Ed.
Back to top
dalu.gelu@gmail.com
*nix forums beginner


Joined: 18 Jul 2006
Posts: 5

PostPosted: Tue Jul 18, 2006 1:12 pm    Post subject: how to use Env variables & its path in ksh shell script Reply with quote

Hi
can anybody let me know how to use the env path & its variable in ksh
script.
Thanks in advance.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [9 Posts] View previous topic :: View next topic
The time now is Fri Nov 21, 2008 11:17 pm | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts User Environment - export PATH variable paalepu AIX 0 Tue Sep 12, 2006 8:12 pm
No new posts does squid 2.6 support setting cache_peer port in redirec... Victor Tsang Squid 0 Fri Jul 21, 2006 8:16 am
No new posts mail script eeb4u@hotmail.com shell 3 Fri Jul 21, 2006 5:50 am
No new posts A simple bash script JPB Suse 2 Fri Jul 21, 2006 2:19 am
No new posts How to set a session cookie with a path? John Drako PHP 1 Thu Jul 20, 2006 7:32 pm

El libro de los nombre | Loans | Samsung | Bad Credit Debt Consolidation | Comcast
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2165s ][ Queries: 20 (0.1259s) ][ GZIP on - Debug on ]