Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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).


In reply to Re^4: Running Under Some Shell by JavaFan
in thread Running Under Some Shell by Xiong

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (7)
    As of 2014-12-26 22:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (176 votes), past polls