use warnings; use strict; use File::Temp qw/tempfile/; use Cwd qw/getcwd abs_path/; use String::ShellQuote qw/shell_quote/; my $SOURCE_FILE = '/tmp/test.sh'; if (!$ENV{PERL_REEXECUTED}) { my ($fh,$fn) = tempfile( DIR=>getcwd, SUFFIX=>'.sh' ); print $fh ". ", shell_quote($SOURCE_FILE), "\n"; print $fh "PERL_REEXECUTED=1 ", shell_quote($^X), " ", shell_quote(abs_path($0)), " \"\$\@\"\n"; print $fh "rm -f ",shell_quote($fn),"\n"; close $fh; exec('/bin/bash','--',$fn,@ARGV)==0 or die $?; }