Hamed Afshar
Hamed Afshar

Reputation: 183

execute shell commands using perl while keeping shell environment variables

I need to run sequential shell commands using perl, but I need the shell environment to keep its variables.

for example:

$result = `cd /`;
$result = `touch test.txt`;

In this example, I need test.txt to be created on /.

Also, I don't want to run them in one line code like $result=touch /test.txt; I need seperate calls to shell while environment variables remain the same.

Upvotes: 0

Views: 290

Answers (1)

Miguel Prz
Miguel Prz

Reputation: 13792

chdir '/';
$result = `touch test.txt`;

Upvotes: 3

Related Questions