LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-13-2010, 12:12 PM   #1
zensunni
Member
 
Registered: Feb 2008
Posts: 45

Rep: Reputation: 0
Why does perl execute bash scripts?


I'm playing with perl and found that I could just go:

"perl /home/me/bash_script.sh"

and it would execute, even though it's not a perl script. Is that just a feature or is there something I'm missing? Why does perl do this?
 
Old 11-13-2010, 03:17 PM   #2
mf93
Member
 
Registered: Jun 2009
Distribution: Debian Squeeze, centOS
Posts: 229

Rep: Reputation: 36
if the script has a shebang (#!/bin/bash) at the beginning it may hand it over to bash to execute. try this on a bash script without a shebang. Im not sure if this is the case, just a thought.
 
Old 11-13-2010, 03:20 PM   #3
Awatto
Member
 
Registered: Aug 2003
Location: Halifax, NS
Distribution: Debian, Gentoo, Ubuntu, Fedora
Posts: 128

Rep: Reputation: 30
Hi zensunni,

afaik, the Perl interpreter will read the Shebang at the beginning and pass the script off to bash. Without this line, the Perl interpreter will try to execute the script itself.
 
Old 11-13-2010, 03:24 PM   #4
Awatto
Member
 
Registered: Aug 2003
Location: Halifax, NS
Distribution: Debian, Gentoo, Ubuntu, Fedora
Posts: 128

Rep: Reputation: 30
You can read about it here:

http://perldoc.perl.org/perlrun.html

And this part may be of interest:

Quote:
If the #! line does not contain the word "perl", the program named after the #! is executed instead of the Perl interpreter. This is slightly bizarre, but it helps people on machines that don't do #!, because they can tell a program that their SHELL is /usr/bin/perl, and Perl will then dispatch the program to the correct interpreter for them.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
proper way to setup notepad++ to execute bash scripts? PiNPOiNT Programming 4 04-25-2009 11:27 AM
how to execute scripts on opened tool from perl? veereshm Linux - Newbie 1 01-21-2009 05:50 PM
Apache2 on Debian won't execute perl cgi scripts, have tried chmod, Options ExecCGI dewert Linux - Software 1 07-03-2006 12:44 PM
how to execute bash scripts from C????? :( cho Programming 2 06-19-2005 07:15 PM
execute bash scripts vapor Programming 9 07-14-2003 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration