Open DabeDotCom opened 1 year ago
hi,
Since you've saved the script in a shell variable already, call the 2nd line in the way below. FindBin will figure it out this time: $ echo '{"one": 1, "two": 2}' | perl -MJSON::JQ -0777 -e "$_PERL" $VAR1 = { 'one' => 1, 'two' => 2 };
Since you've saved the script in a shell variable already, call the 2nd line in the way below. FindBin will figure it out this time: $ echo '{"one": 1, "two": 2}' | perl -MJSON::JQ -0777 -e "$_PERL" $VAR1 = { 'one' => 1, 'two' => 2 };
I'm trying to remember why -e
/-E
didn't Do What I Mean in the first place... I'm sure I wouldn't have put myself through such /dev/fd/###
shenanigans if it weren't strictly necessary.
I do remember running into problems under older versions of Bash 3.x (macOS) trying to run something like:
#!/usr/bin/env bash
perl -E "$(cat <<'END_OF_PERL`
print "HERE!\n";
END_OF_PERL
)"
But $(...)
is definitely more portable than <(...)
— and like the song says: "We don't talk about `backticks`, no no no!" 🎶
(Also, I can't seem to reproduce any of those problems at the moment, even as far back as MacOS 10.6 Snow Leopard! «scratching head»)
Hmm, was it a command-line limit in bash? Then I might have considered (export _PERL; perl -E 'eval $ENV{_PERL}')
... Or did I want to hide/minimize the script contents from ps
and/or ps -e
? No, <(echo "$_PERL")
suffers the same fate... And both -E
and <(...)
seem to handle #line 69
-type directives just fine, which was another thing I thought it might have been.
I'm wondering if maybe it had something to do with passing things into docker? Doubtful: named pipes are even LESS resilient across containers... Quoting issues with bash -c
, perhaps?
Regardless, it's an idiom that I've managed to work into a bunch of utility wrappers and whatnot over the years; this is the first time I've run into a CPAN module that couldn't handle it. ¯\_(ツ)_/¯
PS: I suppose a "more correct" solution might be for me to ask the maintainers of FindBin
(aka Perl/perl5
) if they'll accept a PR to handle -p $0
the same as -e
and -
— i.e., return the current working directory — but I don't know whether there are any esoteric Windows/VMS/AIX gotchas I haven't considered... 🤔
Anyway, thanks for helping me move the ball forward, even if it meant dusting off some really old brain cells! «grin»
I know it might seem a little pathological, but FindBin can die if its script is coming via named pipe:
(I use this technique to generate much more complex query scripts on the fly, for example...)