LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why does perl execute bash scripts? (https://www.linuxquestions.org/questions/linux-newbie-8/why-does-perl-execute-bash-scripts-844075/)

zensunni 11-13-2010 12:12 PM

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?

mf93 11-13-2010 03:17 PM

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.

Awatto 11-13-2010 03:20 PM

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.

Awatto 11-13-2010 03:24 PM

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.


All times are GMT -5. The time now is 10:33 PM.