I'm writing a Perl script that generates a Bash script. I'm using open() with a mode of > to output everything to a new file. Standard stuff:
open (FILEOUT, ">", "rename.sh") or die "Can't create rename.sh";
The resultant .sh file is read only, with an octal value of 444. In perldoc it says I can add a + to the > (open (FILEOUT, "+>", "rename.sh")) to make the newly created file readable and writable, or 666.
Is there a way to make the new file executable (755 or anything else) using open()? If not, what's the best way to set file permissions for the new file?
You will want to chmod the file like this.
chmod 0755, $filename;
#or
chmod 0755, $fh;
Alternatively, if you use sysopen and set the umask appropriately, you can do without chmod.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With