Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which shell does a Perl system() call use?

Tags:

shell

perl

system

I am using a system call to do some tasks

system('myframework mycode');

but it complains of missing environment variables. Those environment variables are set at my bash shell (from where I run the Perl code).

What am I doing wrong?

Does the system call create a brand new shell (without environment variable settings)? How can I avoid that?

like image 270
Lazer Avatar asked Nov 19 '10 12:11

Lazer


1 Answers

It's complicated. Perl does not necessarily invoke a shell. Perldoc says:

If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is /bin/sh -c on Unix platforms, but varies on other platforms). If there are no shell metacharacters in the argument, it is split into words and passed directly to execvp , which is more efficient.

So it actually looks like you would have the arguments passed right to execvp. Furthermore, whether the shell loaded your .bashrc, .profile, or .bash_profile depends on whether the shell is interactive. Likely it isn't, but you can check like this.

like image 168
Matt K Avatar answered Nov 08 '22 05:11

Matt K