[18216] in Perl-Users-Digest
Perl-Users Digest, Issue: 384 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 1 06:10:26 2001
Date: Thu, 1 Mar 2001 03:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983445011-v10-i384@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 1 Mar 2001 Volume: 10 Number: 384
Today's topics:
shell environement variables (Edouard MERCIER)
Re: shell environement variables <gtoomey@usa.net>
Re: shell environement variables ( hans mayer )
Re: shell environement variables <neldredge@hmc.edu>
Re: shell environement variables <spd@daphne.cps.unizar.es>
Re: shell environement variables (Abigail)
Re: Sorting by date <sorryno@email.at.all>
Re: Sorting by date <godzilla@stomp.stomp.tokyo>
Re: Sorting by date <sorryno@email.at.all>
Re: Sorting by date <sorryno@email.at.all>
Re: Sorting by date <godzilla@stomp.stomp.tokyo>
Re: Sorting by date <godzilla@stomp.stomp.tokyo>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 1 Mar 2001 08:54:18 +0000 (UTC)
From: emercier@net2s.com (Edouard MERCIER)
Subject: shell environement variables
Message-Id: <Xns905764C2D67F9emerciernet2scom@202.81.252.27>
Hi to everyone;
So many times I thought into myself "this is a stupid and simple question".
And yet, I've been wandering throughout the web, just in vane: I could'nt
find an answer. Here is my problem.
I wrote a C-shell script which works fine. I had to migrate it into a pure
shell script: I did that "by hand". But now, I have to maintain both of
them. And I'm seek and tired of doing stupid things like that.
The aim of this shell script is just to set some environment variables,
depending on their former state (basically, I just use setenv/export and
some if/then/else procedures).
I've performed some kind of inquiry, and I eventually came to learn PERL
and to write a script which set my environment variables. PERL is supposed
to be supported on all shells, so fine !
The problem is that a PERL-script always run under a new shell-session, so
that all the environment variables set in this PERL-script are lost for the
parent shell-session that invoked it. According to what I understood from
the UNIX philosophy, it is not directly possible to "export" the
environment variables set in a shell-session into its parent shell-session.
My problem is the following: I would like to export environment variable
set in a shell-session into its parent shell-session !!!
So as to work around things, I added the invocation of a new shell at the
end of my PERL-script, so that I get a shell-session with all my new
environement variables. Not very nice, since I have two shells stacked
instead of a single one.
I eventually modified my PERL-script so that it generates my C-
shell/tcsh/sh/bash... script according to the $SHELL - though I'm pretty
sure that there is already something which does the stuf right... This
work, but I eventually wrote a kind of new syntax, a layer above shell-
scripts. I'm not satisfied at all with my work.
This is why I come to you.
Thanks a lot for your attention.
I would appreciate a lot a piece of answer.
Edouard MERCIER
---
Posted via freenews.netfront.net
Complaints to news@netfront.net
------------------------------
Date: Thu, 1 Mar 2001 19:07:49 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: shell environement variables
Message-Id: <y5on6.5944$v5.21691@newsfeeds.bigpond.com>
This is not really Perl related but ...
You can't export environment variables to a perent process!!
There is a linux command called "source" which runs a script as part of the
current process
and does not invoke a new shell.
The linux "bash" man page says the following about source:
" Read and execute commands from filename in the current shell
environment and
return the exit status of the last command executed from filename."
Why do you need environment variables anyway?
Could you use files as you interprocess communication mechanism?
gtoomey
-------------------
"Edouard MERCIER" <emercier@net2s.com> wrote in message
news:Xns905764C2D67F9emerciernet2scom@202.81.252.27...
> Hi to everyone;
>
> So many times I thought into myself "this is a stupid and simple
question".
> And yet, I've been wandering throughout the web, just in vane: I could'nt
> find an answer. Here is my problem.
>
> I wrote a C-shell script which works fine. I had to migrate it into a pure
> shell script: I did that "by hand". But now, I have to maintain both of
> them. And I'm seek and tired of doing stupid things like that.
>
> The aim of this shell script is just to set some environment variables,
> depending on their former state (basically, I just use setenv/export and
> some if/then/else procedures).
>
> I've performed some kind of inquiry, and I eventually came to learn PERL
> and to write a script which set my environment variables. PERL is supposed
> to be supported on all shells, so fine !
>
> The problem is that a PERL-script always run under a new shell-session, so
> that all the environment variables set in this PERL-script are lost for
the
> parent shell-session that invoked it. According to what I understood from
> the UNIX philosophy, it is not directly possible to "export" the
> environment variables set in a shell-session into its parent
shell-session.
>
> My problem is the following: I would like to export environment variable
> set in a shell-session into its parent shell-session !!!
>
> So as to work around things, I added the invocation of a new shell at the
> end of my PERL-script, so that I get a shell-session with all my new
> environement variables. Not very nice, since I have two shells stacked
> instead of a single one.
>
> I eventually modified my PERL-script so that it generates my C-
> shell/tcsh/sh/bash... script according to the $SHELL - though I'm pretty
> sure that there is already something which does the stuf right... This
> work, but I eventually wrote a kind of new syntax, a layer above shell-
> scripts. I'm not satisfied at all with my work.
>
> This is why I come to you.
> Thanks a lot for your attention.
> I would appreciate a lot a piece of answer.
>
> Edouard MERCIER
> ---
> Posted via freenews.netfront.net
> Complaints to news@netfront.net
------------------------------
Date: Thu, 01 Mar 2001 09:26:17 GMT
From: mayer32@relay.bfl.at ( hans mayer )
Subject: Re: shell environement variables
Message-Id: <983438777.438027@bfl-ea1>
hi Edouard !
In article <Xns905764C2D67F9emerciernet2scom@202.81.252.27>,
Edouard MERCIER <emercier@net2s.com> wrote:
>
>My problem is the following: I would like to export environment variable
>set in a shell-session into its parent shell-session !!!
it's not possible
>I would appreciate a lot a piece of answer.
what's the question ?
i assume, you are not happy with the 2 additionl running jobs.
but this is not a performance problem.
if they do nothing, they are swapped out after time.
the only solution can be, solve your problem with shell-syntax.
then you can source the script with the dot syntax as
external program from different scripts.
this the way i do.
--
best regards from vienna |
hans | mayer (at) relay.bfl.at_SPAM
------------------------------
Date: 01 Mar 2001 01:30:15 -0800
From: Nate Eldredge <neldredge@hmc.edu>
Subject: Re: shell environement variables
Message-Id: <83itltj0pk.fsf@mercury.st.hmc.edu>
emercier@net2s.com (Edouard MERCIER) writes:
> The problem is that a PERL-script always run under a new shell-session, so
> that all the environment variables set in this PERL-script are lost for the
> parent shell-session that invoked it. According to what I understood from
> the UNIX philosophy, it is not directly possible to "export" the
> environment variables set in a shell-session into its parent shell-session.
>
> My problem is the following: I would like to export environment variable
> set in a shell-session into its parent shell-session !!!
>
> So as to work around things, I added the invocation of a new shell at the
> end of my PERL-script, so that I get a shell-session with all my new
> environement variables. Not very nice, since I have two shells stacked
> instead of a single one.
>
> I eventually modified my PERL-script so that it generates my C-
> shell/tcsh/sh/bash... script according to the $SHELL - though I'm pretty
> sure that there is already something which does the stuf right... This
> work, but I eventually wrote a kind of new syntax, a layer above shell-
> scripts. I'm not satisfied at all with my work.
This is basically the only way to do it. What's sometimes done is
something like
(foo.pl)
#! /usr/bin/perl
if ($ENV{"SHELL"} eq "sh") {
print("FOO=bar; export FOO");
} else if ($ENV{"SHELL"} eq "csh") {
print("setenv FOO bar");
} # and so on
and then in the shell, do
eval `foo.pl`
so that the shell's output is run in the context of the current shell.
--
Nate Eldredge
neldredge@hmc.edu
------------------------------
Date: 1 Mar 2001 10:19:15 GMT
From: "J.A. Gutierrez" <spd@daphne.cps.unizar.es>
Subject: Re: shell environement variables
Message-Id: <97l7n3$opo$1@news.unizar.es>
In comp.unix.questions Edouard MERCIER <emercier@net2s.com> wrote:
: I wrote a C-shell script which works fine. I had to migrate it into a pure
: shell script: I did that "by hand". But now, I have to maintain both of
: them. And I'm seek and tired of doing stupid things like that.
If your csh script is really simple you could try to translate
it automatically using some script similar to this one:
- c2k ---------------------------------------------------------------------
#!/bin/sh
TEMP=/tmp/c2k.$$
rm -f $TEMP
set -e
touch $TEMP
set +e
trap "rm -f $TEMP" 1 2 3 15
sed \
-e 's/\(if\)\([ ].*\)\(then\)/echo if [ \2 ] \\; \3/g' \
-e 's/==/=/g' \
-e 's/else/echo else/g' \
-e 's/endif/echo fi/g' \
-e 's/(//g' -e 's/)//g' \
-e 's/[ ]*$//g' \
-e 's/#/echo \\#/' \
-e "s/\'/\\\'/g" \
-e 's/\$/\\\$/g' \
-e 's/\~/\\\~/g' \
-e 's/^$/echo/' \
-e '/path.*=/s/path/PATH/g' \
-e '/set[ ]*PATH/s/[ ]*=[ ]*/=/' \
-e '/set[ ]*PATH=/s/[ ]/:/g' \
-e '/set:PATH=/s/set:/set /g' \
$1 > $TEMP
vars=""
set()
{
echo $*
}
alias()
{
name=${1}
shift
echo alias ${name}"="\'${*}\'
}
setenv()
{
vars="${vars}""export ${1};"
echo ${1}"="${2}
}
echo \#
echo \# Translated from $1 by `basename $0`
echo \# `date`
echo \#
. $TEMP
echo "$vars"
unset vars
rm -f $TEMP
---------------------------------------------------------------------------
--
PGP and other useless info at \ La ciencia-ficcion es
http://www.cps.unizar.es/~spd/ \ ese futuro en el que
finger://daphne.cps.unizar.es/spd \ lo seguro es que ya
ftp://ivo.cps.unizar.es/pub/ \ (F. Alfaro) no seremos jovenes
------------------------------
Date: 1 Mar 2001 10:33:50 GMT
From: abigail@foad.org (Abigail)
Subject: Re: shell environement variables
Message-Id: <slrn99s9ce.eh.abigail@tsathoggua.rlyeh.net>
Edouard MERCIER (emercier@net2s.com) wrote on MMDCCXXXIX September
MCMXCIII in <URL:news:Xns905764C2D67F9emerciernet2scom@202.81.252.27>:
!!
!! My problem is the following: I would like to export environment variable
!! set in a shell-session into its parent shell-session !!!
Upgrade your machine to VMS, or accept that it can't be done.
RTFFAQ.
Abigail
--
@;=split//=>"Joel, Preach sartre knuth\n";$;=chr 65;%;=map{$;++=>$_}
0,22,13,16,5,14,21,1,23,11,2,7,12,6,8,15,3,19,24,14,10,20,18,17,4,25
;print@;[@;{A..Z}];
------------------------------
Date: Thu, 1 Mar 2001 08:27:42 -0000
From: "Brian J" <sorryno@email.at.all>
Subject: Re: Sorting by date
Message-Id: <3a9e081d_2@news2.uncensored-news.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:97jgmv$6s7$1@mamenchi.zrz.TU-Berlin.DE...
> According to Brian J <sorryno@email.at.all>:
> > Why?
>
> perl -le 'print time'
> perl -le 'print 200*24*60*60 + time'
>
> Anno
I see, I have tested the forum with false dates and you are correct, the
order gets messed up at precisely 02:46am on the 9th of September this
year. I have however fixed the problem by appending a 0 to the
beginning of the last modified time if it has less than 10 characters.
sub set_modified {
$topic = $filename;
$topic =~ s/(.+)\.txt/$1/;
&open_topic;
$topic_text = join '', @topic_text;
# Extract the date when the file was last modified
if ($topic_text =~ /<last_modified>(.*)<\/last_modified>/s) {
$modified = $1;
if (length($modified) < 10) {
$tmp = "0";
$tmp .= "$modified";
$modified = $tmp;
}
}
else {
$err = "lastmod";
return undef;
}
}
Many thanks.
--
Brian
______________________________________________________________________
Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
With Servers In California, Texas And Virginia - The Worlds Uncensored News Source
------------------------------
Date: Thu, 01 Mar 2001 01:12:36 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sorting by date
Message-Id: <3A9E1284.1EC982B8@stomp.stomp.tokyo>
Brian J wrote:
> Anno Siegel wrote:
> > Brian J wrote:
> > > Why?
> > perl -le 'print time'
> > perl -le 'print 200*24*60*60 + time'
> I see, I have tested the forum with false dates and you are correct, the
> order gets messed up at precisely 02:46am on the 9th of September this
> year. I have however fixed the problem by appending a 0 to the
> beginning of the last modified time if it has less than 10 characters.
Have you decided yet if stat () is supported
by Windows NT?
Godzilla!
------------------------------
Date: Thu, 1 Mar 2001 09:14:43 -0000
From: "Brian J" <sorryno@email.at.all>
Subject: Re: Sorting by date
Message-Id: <3a9e130f_1@news2.uncensored-news.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:97jgmv$6s7$1@mamenchi.zrz.TU-Berlin.DE...
> According to Brian J <sorryno@email.at.all>:
> > Why?
>
> perl -le 'print time'
> perl -le 'print 200*24*60*60 + time'
>
> Anno
I see, I have tested the forum with false dates and you are correct, the
order gets messed up at precisely 02:46am on the 9th of September this
year. I have however fixed the problem by appending a 0 to the
beginning of the last modified time if it has less than 10 characters.
sub set_modified {
$topic = $filename;
$topic =~ s/(.+)\.txt/$1/;
&open_topic;
$topic_text = join '', @topic_text;
# Extract the date when the file was last modified
if ($topic_text =~ /<last_modified>(.*)<\/last_modified>/s) {
$modified = $1;
if (length($modified) < 10) {
$tmp = "0";
$tmp .= "$modified";
$modified = $tmp;
}
}
else {
$err = "lastmod";
return undef;
}
}
Many thanks.
--
Brian
______________________________________________________________________
Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
With Servers In California, Texas And Virginia - The Worlds Uncensored News Source
------------------------------
Date: Thu, 1 Mar 2001 09:20:00 -0000
From: "Brian J" <sorryno@email.at.all>
Subject: Re: Sorting by date
Message-Id: <3a9e145d_1@news2.uncensored-news.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3A9E1284.1EC982B8@stomp.stomp.tokyo...
> Brian J wrote:
>
> > Anno Siegel wrote:
> > > Brian J wrote:
>
> > > > Why?
>
> > > perl -le 'print time'
> > > perl -le 'print 200*24*60*60 + time'
>
> > I see, I have tested the forum with false dates and you are correct,
the
> > order gets messed up at precisely 02:46am on the 9th of September
this
> > year. I have however fixed the problem by appending a 0 to the
> > beginning of the last modified time if it has less than 10
characters.
>
>
> Have you decided yet if stat () is supported
> by Windows NT?
>
> Godzilla!
I don't know, I pressume it doesn't. I looked in my Perl book and it
just says "The actual values in the list differ slightly depending on
which operating system you're running because some operating systems
include features that others might not implement".
--
Brian
______________________________________________________________________
Posted Via Uncensored-News.Com - Still Only $9.95 - http://www.uncensored-news.com
With Servers In California, Texas And Virginia - The Worlds Uncensored News Source
------------------------------
Date: Thu, 01 Mar 2001 01:45:09 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sorting by date
Message-Id: <3A9E1A25.D84F19A8@stomp.stomp.tokyo>
Brian J wrote:
> Godzilla! wrote:
> > Brian J wrote:
> > > Anno Siegel wrote:
> > > > Brian J wrote:
> > Have you decided yet if stat () is supported
> > by Windows NT?
> I don't know, I pressume it doesn't. I looked in my Perl book and it
> just says "The actual values in the list differ slightly depending on
> which operating system you're running because some operating systems
> include features that others might not implement".
stat () is supported by all systems except
Novell Netware and DOS/PM.
_stat() is supported by all systems except DOS/PM.
Godzilla!
------------------------------
Date: Thu, 01 Mar 2001 02:20:52 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sorting by date
Message-Id: <3A9E2284.DBF65EC5@stomp.stomp.tokyo>
Brian J wrote:
> Anno Siegel wrote:
> > Brian J wrote:
(snippage)
> I see, I have tested the forum with false dates and you are correct, the
> order gets messed up at precisely 02:46am on the 9th of September this
> year. I have however fixed the problem by appending a 0 to the
> beginning of the last modified time if it has less than 10 characters.
September 9 2001 at 01:46:40 hours
@Array = sort {$a <=> $b} @Array is a
significantly more logical solution.
Godzilla!
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 384
**************************************