Have you looked at system? How did it fail to work for you?
I suggest doing something like
my $command= "/usr/bin/bash -c 'do $some_file'";
system( $command ) == 0
or die "Couldn't launch '$command': $! / $?";
| [reply] [d/l] |
Hello Say I have a file containing a single line which is a bash command. Is ther a Perl one liner to copy and run it? Cheers
Just to be sure, you do want to do this within the context of a larger Perl script, right? Since otherwise, you don't even need Perl; the following will suffice:
$ source filename.txt
| [reply] [d/l] |
You can execute a shell-script as if it were any other system command ... but I would caution you to be very careful with this. Generally speaking, when I am reading a piece of source-code to understand how it works, I do not want to have to branch-off to read another source-file, especially not one that is written in a totally different language and especially not one that in effect steps-away from the Perl context completely to do whatever it does. If this file contains a single line, I’d rather see that single-line within the Perl source. And I must say that I am not too keen on “one-liners” much either, because brevity sacrifices clarity. These practices are much less maintainable than other alternative choices for doing the same things, and I would strongly encourage you to champion maintainability as much as it makes sense in your work.
| |
because brevity sacrifices clarity
Well... One of the most popular reasons to do overcomplicated things like this is to hide your command in bash, thus clarity probably is not the main goal here
Just think before to do what you want to do, that there is always a bigger dog than oneself even if you try to cover your own traces. Read about the special bash variable $0
perl -e 'system("\$0 < mybashscript.sh");'
You should better try to traduce your script to perl code instead if you want to call it from perl
| [reply] [d/l] |