dotsh.pl replacement

M

Mark D. Tischler

In a quick search in this newsgroup, I see no discussion
concerning dotsh.pl, so I'm hoping that this hasn't been
previously discussed. If so, my apologies.

The header in the 5.6.1 version of dotsh.pl says that it isn't
being maintained any longer. Is there a replacement for it?
The reason I'm asking is because we have discovered that when
using it, it puts single quotes around the value for a
variable, which is undesirable, especially to Java. So, if I
execute:
&dotsh("file");
where "file" has a series of variable=value lines, including, e.g.:
VAR=val
and, if I then do:
print "VAR=$VAR\n";
in my Perl script, I get:
VAR='val'
whereas I would have expected:
VAR=val
Thanks for any assistance anyone can provide in either getting
around this problem or using a new and improved version or
equivalent of dotsh.

Mark Tischler
(e-mail address removed)
 
G

Greg Bacon

: [...]
: Thanks for any assistance anyone can provide in either getting
: around this problem or using a new and improved version or
: equivalent of dotsh.

Abigail has posted the following trick:

# Filename shouldn't have single quotes in it.
my $ENVIRONMENT = "/some/file/with/environment/variables/";

if (@ARGV && $ARGV [0] eq '--sourced_environment') {
shift;
}
else {
if (-f $ENVIRONMENT) {
#
# Now we perform a double exec. The first exec gives us a shell,
# allowing us the source the file with the environment variables.
# Then, from within the shell we re-exec ourself - but with an
# argument that will prevent us from going into infinite recursion.
#
# We cannot do a 'system "source $ENVIRONMENT"', because
# environment variables are not propagated to the parent.
#
# Note the required trickery to do the appropriate shell quoting
# when passing @ARGV back to ourselves.
#
# Also note that the program shouldn't normally be called with
# '--sourced_environment' - if so, pick something else.
#

@ARGV = map {s/'/'"'"'/g; "'$_'"} @ARGV;

exec << " --";
source '$ENVIRONMENT'
exec $0 --sourced_environment @ARGV;
--
die "This should never happen.";
}
}

NB: zap the leading four spaces on the code above so the compiler can
find the here-document terminator. It'd be sweet if Perl 6 would
provide a way to work around these concerns of typography.

Hope this helps,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top