Using python on Mac OS, I would like to open a file for writing and put some shell commands into it. Later to be run in terminal.
with open("my_script.sh", "w") as fd:
fd.write("#!/bin/sh\n")
fd.write("echo $PATH\n")
This will create the file, but I could not figure how to set the execute bit so when I run it in the Terminal I will not get:
sh: my_script.sh: Permission denied
import os
os.chmod("my_script.sh", 0744)
Pick the value properly though. Some values might not be safe.
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