| Author |
Message |
Jon LaBadie *nix forums beginner
Joined: 06 May 2006
Posts: 46
|
Posted: Thu Jul 20, 2006 12:19 pm Post subject:
Re: how to use Env variables & its path in ksh shell script
|
|
|
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
|
Posted: Thu Jul 20, 2006 10:33 am Post subject:
Re: how to use Env variables & its path in ksh shell script
|
|
|
"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
|
Posted: Thu Jul 20, 2006 7:55 am Post subject:
Re: how to use Env variables & its path in ksh shell script
|
|
|
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
|
Posted: Thu Jul 20, 2006 7:14 am Post subject:
Re: how to use Env variables & its path in ksh shell script
|
|
|
| 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
|
Posted: Wed Jul 19, 2006 2:53 pm Post subject:
Re: how to use Env variables & its path in ksh shell script
|
|
|
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
|
Posted: Wed Jul 19, 2006 1:50 pm Post subject:
Re: how to use Env variables & its path in ksh shell script
|
|
|
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
|
Posted: Wed Jul 19, 2006 10:48 am Post subject:
Re: how to use Env variables & its path in ksh shell script
|
|
|
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
|
Posted: Tue Jul 18, 2006 1:46 pm Post subject:
Re: how to use Env variables & its path in ksh shell script
|
|
|
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
|
Posted: Tue Jul 18, 2006 1:12 pm Post subject:
how to use Env variables & its path in ksh shell script
|
|
|
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 |
|
 |
|