$ cat tmp.sh
#!/tools/bin/bash
echo $BASH_VERSION
$ cat tmp.pl
#!/usr/local/bin/perl
use strict;
use warnings;
use DBI;
use CGI;
system("tmp.sh");
$ tmp.sh
3.2.48(1)-release
The result is as expected.
$ tmp.pl
3.2.25(1)-release
The result is not as expected.
The shell directive in tmp.sh does not work.
Can anybody tell me why?
How to correct it?
Thanks.
system() accepts as argument either a scalar or an array. If the argument is a scalar, system() uses a shell to execute the command ("/bin/sh -c command");
If the argument is an array it executes the command directly, considering the first element of the array as the command name and the remaining array elements as arguments to the command to be executed.
So try:
$ cat tmp.pl
#!/usr/local/bin/perl
use strict;
use warnings;
use DBI;
use CGI;
system("tmp.sh", "");
1 Like
chubler_xl:
system("tmp.sh", "");
I don't see how that can possibly make a difference. Whether perl or /bin/sh execs the script, it is the exec(2) syscall that will load the interpreter; in both cases, it will be the same, /tools/bin/bash.
Did I miss something there?
Regards,
Alister
For some reason, the perl script loads a different version of bash than the shell script.
Yes there is something very strange on that server, I wonder what result the OP would get from:
$ /bin/sh -c tmp.sh
$ /bin/sh -c tmp.sh
3.2.25(1)-release
I also found another way to solve the issue.
$cmd="/tools/bin/bash -c 'tmp.sh a b c'";
system($cmd);