ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Can any one tell me how to run a shell script through perl with example?
It's a bad idea, in my experience. It's better either to run the shell script as a shell script or to rewrite it in Perl. (That means more than simply passing commands to the shell via Perl. It means writing it to Perl's strengths and weaknesses.)
Can you show the script and say a bit more about why you want to do it this way?
Last edited by Telemachos; 03-17-2009 at 07:21 AM.
It's a bad idea, in my experience. It's better either to run the shell script as a shell script or to rewrite it in Perl. (That means more than simply passing commands to the shell via Perl. It means writing it to Perl's strengths and weaknesses.)
Can you show the script and say a bit more about why you want to do it this way?
Maybe the OP just meant running any executable through 'system' ?
not pertaining to this thread. Few reasons (not just shell scripts) i can think of.
1) the script works, but take up too much resources. therefore needs to rewrite to make it better.
2) company is revamping their scripting standards. scripts will be written in one particular language for a "uniform" environment. They don't want shell, perl, ruby etc scripts all lying around.
3) the script works, but due to new business processes and requirement, it has to be rewritten to cater for these new processes.
Maybe the OP just meant running any executable through 'system' ?
You may be right, but the OP asked how to do this for a 'shell script', and by that I took him to mean a script for Bash or Ksh or whatever.
One thing to add to Ghostdog's reasons: a well-written Perl program should be more portable than a shell script (which will often rely on particular implementations of sed, grep and company).
Last edited by Telemachos; 03-17-2009 at 08:21 AM.
...
One thing to add to Ghostdog's reasons: a well-written Perl program should be more portable than a shell script (which will often rely on particular implementations of sed, grep and company).
I agree with that - whenever I try to write something in shell in an hour I'm asking myself "why haven't I written this in Perl ?".
I do, however, in certain cases generate shell scripts from my Perl scripts, but these shell scripts are just plain sequential commands.
The point is that contents of these scripts are not known until some pretty complex processing is done in Perl; after that the shell scripts are kind of "exported intelligence" from Perl, and can be used separately.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.