Question

Perl Shell Scripts

Asked by: BPMonk

Just a question to try and get my head round Perl and Shell scripts.  I know that their is different shell scripts which can be written in BASH,sh and C etc.  My questions is this.  Is their such a thing as a Perl Shell Script? I know you can call Perl Scripts from within a Shell but what would be a PERL Shell Script example?  

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-02-18 at 05:22:29ID23171196
Tags

perl

,

5

Topics

Shell Scripting

,

Perl Programming Language

Participating Experts
5
Points
500
Comments
10

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. perl->shell?
    Is there any way to run shell commands from perl script? Shell perl module only seems to support most simple ones like ls, cat etc... Anyway, something like this #!/usr/bin/perl print "Content-type: text/html \n\n"; use Shell qw[w]; print w; does not work - neith...
  2. Need links for learning perl,unix,bash,shell scripts...
    Need links for learning perl,unix,bash,shell scripts...
  3. shell to perl conversion
    Hi, Can someone please help me with a perl program equivalent to the attached shell script ? The idea is to count the no. of lines deleted/added in all the patch files saved in a directory and write the output to a text file. All the more good if it can be directrly written...
  4. calling perl varibles in a shell script
    Hi How can we call perl variables in a shell script? Can somebody give an example? Thanks

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: sjm_eePosted on 2008-02-18 at 05:47:12ID: 20919810

There is no such thing as "a perl shell script" as there is no "shell" whose scripting language is "perl". However, both perl scripts (aka programs) and shell scripts can be run by Unix-like environments by putting them in a executable file as follows:

#!/bin/sh
# The following is a shell script
echo "Hello World!"

#!/usr/bin/perl
# The following is a perl program
print "Hello World!"

Both of these work because of the way that a Unix-like environment treats executable files starting with the character sequence hash-exclamation.

 

by: BPMonkPosted on 2008-02-18 at 05:59:02ID: 20919911

Ok, but u have to execute the Perl script within the shell dont u?  And is it the case you can do a lot of shell script stuff with PERL i.e i/o file manipulation etc.  So if you wanted to move files fro, Dir Aa to B you would use the appropriate sh commands (Im assuming sh here).  But, if for some reason you wanted to do the same with PERL you would srite the perl script but you would still have to call the script from within sh so effectively you would need to enter the appropriate sh to call the Perl script...

 

by: Adam314Posted on 2008-02-18 at 07:12:31ID: 20920495

What makes it a shell script is that the interpreter can also be used as a shell.  You don't have to use the scripting language of the shell you are using.  You can use bash as your shell, but use ksh to interpret a script.
For a perl script, perl does not have a shell.  The perl script can be started many ways.  It could be started by cron, by a webserver, another perl script, a shell script, user at a command line, or if you have a graphical interface by clicking an icon configured to run the perl script.

 

by: ozoPosted on 2008-02-18 at 09:47:03ID: 20921915

shell scripts are scripts written in the language of a particular shell
perl scripts are scripts written in Perl
Not to confuse things, but there are also these
http://search.cpan.org/~ferreira/Shell-Perl-0.0015/lib/Shell/Perl.pm
http://search.cpan.org/~pardus/Zoidberg-0.96/man1/zoiduser.pod

 

by: FishMongerPosted on 2008-02-18 at 09:52:20ID: 20921965

I like stirring the pot :)

The Perl Shell (psh): It aspires to be your primary login shell.
http://sourceforge.net/projects/psh/
http://www.focusresearch.com/gregor/sw/psh/

 

by: sjm_eePosted on 2008-02-19 at 01:59:39ID: 20926951

Note to self:

Google returns a very different first page of results with "perl shell script" and "perl shell".

 

by: siliconbritPosted on 2008-02-19 at 05:10:02ID: 20927886


Like everything else in the world of software, the confusion comes from the way we use our terminology flexibly, or "loosely" if you like.  There is nothing wrong with this flexibility.  In fact the confusion that ensues, often leads to change.

So, the answer to your question is 'Yes - there is such a thing as a Perl Shell Script'.

There are two possible interpretations of your question:

Firstly, because many people use the term "Shell Script" to describe *any* script that can be executed under *any* shell, then a Perl script *is* a shell script by default.  It's like the phrase 'Shell Script' means a script that is eligible to run under a shell.  This doesn't make the definition correct, and in fact it isn't correct.  The correct definition of a shell script is a script that will run under *this* shell, whatever that shell may be.  If *this* is what you meant by your question, then *any* perl script is an example of a script that runs under a shell.  It doesn't really make a perl script a shell script, but that description will do for most cases.

Secondly, there is also a genuine Perl Shell, called psh.  It's not fantastic, but it's workable, and in that shell, anything you type will be evaulated as a Perl syntaxed command.  You can also group commands into a file (script) and execute that file as a single command, so it is a genuine perl shell, and again any perl script will suffice as an example of a script that will run under psh, although there are a few minor  differences.



Finally, there may be one other piece of information you do not know.  Any script from any shell installed on a server can be made to run under the current shell even if it's different by making a few changes to make that script a unix program.  So, to execute a perl script from under the bourne shell:

1) Add the following line as the FIRST line in your perl script (assuming /usr/bin/perl is the location of perl):

  #!/usr/bin/perl

2) Set the execute bit on the script:

  chmod +x filename.pl

3) Test it:

  ./filename.pl


To avoid any arguments or further debate on the definition of the word 'script' in this context, please consider accepting the following assertions:

1) The word 'script' was coined when there was only one shell, and it refers to a number of commands that can be typed at a prompt being grouped into a file and executed in one go.  Just a simple timesaver.

2) The word shell was coined to describe the program that manages the command line interface, interpreting what you type into system calls.  The word shell is related to the 'layers' of the operating system.  There was a shell *before* bourne shell (/usr/bin/sh) in which you could type system calls, so it is not sufficient to limit the use of the work to the common command interpreters (bash, sh, ksh etc).  The only real requirement is that when the shell is running, you can type commands and they will be processed.  So, what would you call what happens when you type 'perl' at a unix command line (with perl installed! ;) )?

 

by: BPMonkPosted on 2008-02-19 at 05:54:40ID: 20928251

Good definition, well put across I might also add.  However, my interpretation of a Shell script is something which performs the monotonous OS system maintenance tasks.  So in the context of BASH OR SH typing in its native code to PIPE, GREP or whatever combination to produce a script which alleviates the laborious tasks of manually step by step execution.  Then I hear the term 'Shell scripting with Perl' which is where I get confused.  When we use these phrases in the same context does this mean that a perl script is invoked under a specific shell which does specific shell scripting tasks such as user/disk maintenance or any OS specific task etc.  This is where I get confused ya see...  Im quite proficient with Bourne, well used to be, but have had little experience with Perl and absolutely no experience of combining the 2...???

 

by: siliconbritPosted on 2008-02-19 at 07:15:56ID: 20929066

I think that you have a good handle on this, and you are one step away from figuring it all out.

The reason people use the term "Shell scripting with Perl" is because perl is chiefly an interpreted language in much the same way as any unix shell.  (interpreted as text rather than 'translated' (compiled) into machine code).

You can write perl scripts to run most of the user-level activies that you might normally write in a shell language.  This might include writing data reports, performance reports, delivering webpages, automating email alerts, all these sorts of things and probably a gerjillion more.

Perl is an extremely powerful scripting language, and yes there are tools and techniques to be able to manage and execute the system commands in much the same way as you do with shell languages such as bourne, bash etc.

This means that perl is also well placed for writing *high-level* administration scripts, perhaps to start/stop an application, or filter information from the output of commands like 'ps' and so forth.  But like any other language, including the UNIX shells, you have to learn a new syntax and it is always good practice to write lots of small tools and use the unix pipe to combine them.

As an example - perl includes some quite advanced and very useful regular expression functions, which can be used to build complex searching and finds demonstrably quicker than bash/sh/ksh.  There are also utilities and syntax that overcome some limitations of the shells, such as associative arrays which can be very useful when reporting on large data sets.

However for most tasks that require some sort of serious OS task, like configuring IP addresses, mounting/unmounting filesystems, I personally would recommend that you stick with the shell languages, not least because the tools are easier to maintain by *more* people, and when you are dealing with a critical UNIX problem, it's better to stick with the shell tools.

If you have a specific question, or would like a specific example - post back.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...