Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: Running Under Some Shell

by JavaFan (Canon)
on Feb 25, 2010 at 12:44 UTC ( #825284=note: print w/replies, xml ) Need Help??


in reply to Re^3: Running Under Some Shell
in thread Running Under Some Shell

Oh sorry. I wanted to refer to another gubbin, namely the second example in perlrun, that's the "more baroque" in the OP.
Ah, you mean the
eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}' & eval 'exec /usr/bin/perl -wS $0 $argv:q' if $running_under_some_shell;
Let me try to explain. First, since "eval" is valid Perl, and so are the & and && operators, Perl will never execute any of it, because $running_under_some_shell is false.

$?0 is special csh construct, returning 1 if the current filename is known, 0 otherwise. $? is the exit status of the most recent pipeline in sh. Since (exit $?0) is executed in a subshell (due to the parens), and from a file, eval '(exit $?0)' will return 0 in sh, but 1 in csh. This means, the eval 'exec perl -wS $0 ${1+"$@"}' is only executed by sh. But when executed by sh, sh will not see anything else of the file.

Which leaves use with & eval 'exec /usr/bin/perl -wS $0 $argv:q'. I do not quite know how csh parses that - I can only assume csh allows a "null command" - which is then put in the background. Then it executes /usr/bin/perl -wS $0 $argv:q. We already know the meaning of the -wS $0 part. $argv is a variable holding all the arguments to the program. The :q is a modifier, quoting all the arguments (just like "$@" does in sh).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://825284]
help
Chatterbox?
[Corion]: I've started that again this month (now forever instead of a limited time), and it already destresses me a lot
[holli]: There are Anti Vaxxer weeks at IKEA.
[Corion]: Of course, it's a 20% cut in the money I receive, while the work doesn't necessarily reduce at all, but my approach is to make the work take longer instead of fitting 5 days worth of work into 4
[holli]: 50% off all children coffins.
[Corion]: holli: Ooof :)
[hippo]: Cut should beless than 20% after tax, though. :-)
[Corion]: hippo: Yeah, but at least two years ago, it still was close enough to 20% cut
[Corion]: But I have a very positive experience with a four day workweek and a three day weekend. I can't easily go back though to full money.
[Corion]: That is easy without having to pay for a house, a wife or children though. If I had any of these, or any two of these, the decision wouldn't be that easy.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2017-09-21 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (249 votes). Check out past polls.

    Notices?