Well, you have several options you could try, depending on exactly what you want to do. First, you can use either the exec() or the system() perl functions. They are very simlar, but with one essential difference. If you use the exec() function, then the perl script terminates once it reaches the exec() function in the perl script. It will never return to the script, and any other lines in the script occurring after the exec() will not be executed. On the other hand, the system() function will return control to the perl script after executing the passed shell commands. If the command(s) were a success, the system() function returns 0, otherwise it returns a value of 1 or greater for a failure. So use exec() if it will be the last or only line to be executed in your perl script, otherwise use the system() function if it is in the middle of your script. Below, I will give a few examples of things you might try.
First, let's try creating a folder and then duplicating it in a Perl script.
Code:
#!/usr/bin/perl
system("mkdir ./newdir; cp -R ./newdir ./newdir2");
I could have also used the exec() function since I only have one function in the script, but I'm sure your script is much more complex.
Now lets create a shell script to create the new folder and duplicate it. We'll name it "test.sh."
Code:
#!/bin/sh
mkdir ./newdir
cp -R ./newdir ./newdir2
Now let's execute "test.sh" from our Perl script.
Code:
#!/usr/bin/perl
system("sh ./test.sh");
Once again, I could have also used the exec() function here, if it was the last or only line to be executed in my perl script. Otherwise, use system().
I just used the "mkdir" and "cp" in my examples since you had asked about these specifically. You could use any shell commands you like in the manner I did above with "mkdir" and "cp." Also, if you are having the Perl script generate the shell script you want to execute and saving it, you'll want to use "chmod" in your script after you generate the script and make it executable. Hope this helps