Operating System - HP-UX
1836492 Members
2495 Online
110101 Solutions
New Discussion

preserve env when run ksh

 
Lai Nee Shyang_1
Frequent Advisor

preserve env when run ksh

Hi There,

Can I run ksh or sh (spwan a shell) but inherit the parent's env setting (.profile) ??

Not sure if this is posted before, if yes please direct me to the relevant posting.

Thank u.

Lai
If it doesn't work, We'll make it work. If it works, We'll make it work better.
6 REPLIES 6
Nicolas Dumeige
Esteemed Contributor

Re: preserve env when run ksh

Hello,

Sub shell normaly get their ancestor environnement.

Can you be more specific ...

Cheers

Nicolas
All different, all Unix
Mark Grant
Honored Contributor

Re: preserve env when run ksh

YOu can only do this by exporting the variables from the parent ("export VARIABLE") or, in your case, re-reading the .profile using ". .profile". If the sub-shell is started via "exec" you can give it a parameter of "-" to make it a log in shell.
Never preceed any demonstration with anything more predictive than "watch this"
Lai Nee Shyang_1
Frequent Advisor

Re: preserve env when run ksh

Hi ,

Sorry, you are right. comparing the env before and after I do a ksh, the env are the same. But somehow PS1 setting seems to be lost.

Is there a way to preserver PS1 setting then ?


Thanks

Lai
If it doesn't work, We'll make it work. If it works, We'll make it work better.
Lai Nee Shyang_1
Frequent Advisor

Re: preserve env when run ksh

Hi Mark and Nic,

THanks.. I think I got it.

Lai
If it doesn't work, We'll make it work. If it works, We'll make it work better.
Bharat Katkar
Honored Contributor

Re: preserve env when run ksh

Sub shell normally inherit all the exported variables. And about env variable, they are always exported.
For local varibale like say we have VAR1 then:
#
# VAR1=green
# echo $VAR1
green
# ksh
# echo $VAR1 (** nothing is displayed below)

# exit
# export VAR1=green
# ksh
# echo $VAR1
green
#
# exit
# echo $VAR1
green
#

I hope this makes it clear.
You need to know a lot to actually know how little you know
Jose Mosquera
Honored Contributor

Re: preserve env when run ksh

Hi,

From your .profile file or inside of your current environment invokes the execution of the new deppending environment throught the following sintax:
. ./new_script
^
This first dot is the key!

Where new_script is the file that contains the dependences of variables defined in the file .profile.


Rgds,