in reply to Re: wrapping bash and astronomy
in thread wrapping bash and astronomy
Ok, so it's clear now that have to tell it to find bash:
my $capture = capturex "bash","2.create.bash", "@ARGV"; $logger->info("capx: $capture");
I got a strong result with wrapping 2.create.bash, which I think is a nifty little utility for my nomenclature scheme.
HOWEVER! I assume that capturex, systemx and friends spawn a system command directly or via an ephemeral shell which ends as soon as the shell command ends. This means that a sequence of capturex calls will use completely different shells, which will not share any state. So, setting shell options via set -eu on one capturex call will not be preserved on the next capturex call. If you want to preserve state in a shell and execute many shell commands in it there is a simple way: first create a temporary shell script (see tempfile of File::Temp) within your perl-script to contain all the commands you want to run. And then execute this shell script via a single capturex call.fritz@laptop:~/Documents/gitlab1$ ./4.wrap.pl 2.millcreek.pl Time is Thu Mar 2 01:43:55 2023 Julian day is 2460005.86383102 ./4.wrap.pl capx: The shebang is specifying bash Using bash 5.0.17(1)-release 2 3 3.millcreek.pl -rwxrwxr-x 1 fritz fritz 11K Mar 2 01:43 3.millcreek.pl fritz@laptop:~/Documents/gitlab1$
I'm trying to follow, and I have a script to that end:
#!/usr/bin/perl use v5.030; # strictness implied use warnings; use Path::Tiny; my ($path) = @ARGV; if (not defined $path) { die "Need path in\n"; } my $file_in = path("$path"); my @lines = $file_in->lines_utf8; my @matching; for my $line (@lines){ if ( $line =~ /^#*$/){ say "line matched $line"; next; } else { push( @matching, $line ); } } say @matching; say "cardinality: ", scalar @matching; my $target_dir = path('/tmp'); my $tempfile = $target_dir->tempfile('foobarXXXXXX'); $tempfile->spew("@matching"); # not atomic __END__
Output. I can't figure out why the shebang and comments endure:
fritz@laptop:~/Documents/gitlab1$ ./1.wrap.pl 3.git.sh line matched #!/bin/bash pwd >2.txt #echo "starting fresh with rm -rf .git" #rm -rf .git | tee 1.txt #git init #ls >README.md git add *.pl git add *.sh git add *.txt #git remote add origin git@gitlab.com:perlmonks/$1.git git commit -m 'next revision' | tee 2.txt git push -uf origin master | tee 2.txt #git push -uf master main | tee 2.txt cardinality: 13 fritz@laptop:~/Documents/gitlab1$
Question: How is my regex not sieving out the comments? Do you see what I'm trying to pull off here?
Aldebaran++ I have to commend your efforts not only in using Perl but also in using Linux. It's a steep learning curve but it hides a ... springboard at the end of it. Plus the methodical approach you take in achieving your aims.Woo-hoo, a springboard! If the board is at the height of Skylla, and extends to the center of Charybdis, how long does one fall until impact?
Cheers,
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: wrapping bash and astronomy
by kcott (Archbishop) on Mar 02, 2023 at 11:00 UTC | |
by Aldebaran (Curate) on Mar 08, 2023 at 06:34 UTC |