sh & export

Matthew Seaman matthew at FreeBSD.org
Tue Jan 29 06:39:30 UTC 2013


On 29/01/2013 01:11, kpneal at 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 268 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20130129/38f82002/attachment.sig>


More information about the freebsd-questions mailing list