Re: sh & export

2013-01-28 Thread Matthew Seaman
On 29/01/2013 01:11, kpn...@pobox.com wrote:
> On Mon, Jan 28, 2013 at 07:41:35PM -0500, Fbsd8 wrote:
>> This is what I am looking at in a sh script
>>
>> echo export jail_${jailname}_hostname=\"${jailname}\"
>> puts it into the env
>> and this brings it back out
>> eval jailname=\"\$jail_${jailname}_hostname\"
>>
>> Question is how can I display from the console command
>> line what has been exported?
>>
>> env issued on the console command line does not show
>> any thing named jail.
> 
> Environment variables are only exported to children of the shell that
> created or inherited them. When you run a script you normally have your
> command line shell start a child shell which then executes the script.
> When the child shell that runs the script finishes the script it ends and
> control returns to the parent. The child's environment at this point is
> gone, but the parent couldn't have looked at it anyway. Parents don't
> really know what their children are doing.
> 
> So, to answer your question above, "You can't display from the console
> what was set in a script."
> 

I'm afraid that's simply not true.  ps(1) has a '-e' flag which can show
you the environment for any process.  However, since printing out the
environment will easily overflow the console width that ps(1) uses by
default, it's best to combine it with a couple of 'w's.

Thus:

ps -wwwe ${pid_of_process}

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.
PGP: http://www.infracaninophile.co.uk/pgpkey




signature.asc
Description: OpenPGP digital signature


Re: sh & export

2013-01-28 Thread Fbsd8

kpn...@pobox.com wrote:

On Mon, Jan 28, 2013 at 07:41:35PM -0500, Fbsd8 wrote:

This is what I am looking at in a sh script

echo export jail_${jailname}_hostname=\"${jailname}\"
puts it into the env
and this brings it back out
eval jailname=\"\$jail_${jailname}_hostname\"

Question is how can I display from the console command
line what has been exported?

env issued on the console command line does not show
any thing named jail.


Environment variables are only exported to children of the shell that
created or inherited them. When you run a script you normally have your
command line shell start a child shell which then executes the script.
When the child shell that runs the script finishes the script it ends and
control returns to the parent. The child's environment at this point is
gone, but the parent couldn't have looked at it anyway. Parents don't
really know what their children are doing.

So, to answer your question above, "You can't display from the console
what was set in a script."


OK then from within a script what single command would show everything?
I tested with a script with only the env command and did not get any 
thing more than issuing env from the console command line.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: sh & export

2013-01-28 Thread Fbsd8

Lowell Gilbert wrote:

Fbsd8  writes:


I'm reading a script and i see a lot of exports.

Is there some command to display the exported environment?

The env command does not show them. Only see things made by setenv command.


You're not clear on which shell the script is using. 
The subject line implies /bin/sh, but that doesn't
have a setenv command. 

I don't think there's a direct way to show exported 
variables in /bin/sh, but starting an inferior shell 
and looking at the environment there should do it.





This is what I am looking at in a sh script

echo export jail_${jailname}_hostname=\"${jailname}\"
puts it into the env
and this brings it back out
eval jailname=\"\$jail_${jailname}_hostname\"

Question is how can I display from the console command
line what has been exported?

env issued on the console command line does not show
any thing named jail.



___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: sh & export

2013-01-28 Thread Polytropon
On Mon, 28 Jan 2013 18:55:02 -0500, Fbsd8 wrote:
> I'm reading a script and i see a lot of exports.
> 
> Is there some command to display the exported environment?

Yes, sh's builtin "env" does this.



> The env command does not show them. Only see things made by setenv command.

It seems you're mixing shells here. The C Shell uses setenv
to set variables, printenv to list them. The systems's sh
uses export to set variables, and env to print them.

Example (with exported and non-exported variable:

$ export ASDF=yxcvbnm
$ env | grep ASDF
ASDF=yxcvbnm

$ JKL=qwertzuiop
$ env | grep JKL
$ echo $JKL
qwertzuiop

And compare for the C shell:

% setenv ASDF yxcvbnm
% printenv | grep ASDF
ASDF=yxcvbnm

% set JKL=qwertzuiop
% printenv | grep JKL
% echo $JKL
qwertzuiop

If you omit the "| grep" step, the full list will be printed.



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: sh & export

2013-01-28 Thread Lowell Gilbert
Fbsd8  writes:

> I'm reading a script and i see a lot of exports.
>
> Is there some command to display the exported environment?
>
> The env command does not show them. Only see things made by setenv command.

You're not clear on which shell the script is using. 
The subject line implies /bin/sh, but that doesn't
have a setenv command. 

I don't think there's a direct way to show exported 
variables in /bin/sh, but starting an inferior shell 
and looking at the environment there should do it.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: sh & export

2013-01-28 Thread Ralf Mardorf

On Tue, 29 Jan 2013 00:55:02 +0100, Fbsd8  wrote:

The env command does not show them.


Does set or printenv show them?
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


sh & export

2013-01-28 Thread Fbsd8

I'm reading a script and i see a lot of exports.

Is there some command to display the exported environment?

The env command does not show them. Only see things made by setenv command.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"