I don't know what exactly you are looking for, the basic difference is that shell script will be interpreted by the appropriate shell binary (for example /bin/bash, /bin/ksh), whereas the perl script will be compiled and interpreted by the perl binary (e.g. /usr/bin/perl).

One practical difference is that the shell comes in a variety of flavours and you can never know which shell binary will be executed on a system your shell script gets copied to. Usually shell scripts call /bin/sh , which on many systems is just a symlink to the systems preferred shell. While it is usually not extraordinarily difficult to write shell scripts which are portable between different shell flavours, this does require some knowledge and diligence on the part of the script author. A perl script will always run in perl, which is mostly the same across *NIX systems, so you do not need to worry about incompatibilities between different systems as much (as long as you take care that your script works under the commonly installed version of perl, and not just the most recent one). Thus, for certain usage scenarios, Perl scripts are more portable between systems than shell scripts.

Another practical difference is that the shell on it's own doesn't do very much, shell scripts are usually used to call external programs (mv,find,ls,sed to name a few). So again you are somewhat dependant on the environment that your script find, because different systems will have different variants of these utilities installed which may exhibit different behaviour. A lot of Perl scripts OTOH do useful work without depending on external processes, so again you have a better chance of easy portability between disparate systems and, depending on what you do, better performance.

A good answer to your question really depends on why you're asking it :-)


Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan

In reply to Re: Difference between a perl script & shell script by tirwhan
in thread Difference between a perl script & shell script by Anonymous Monk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.