Create python script executable
- By Preneesh AV --
- 20-Nov-2019 --
- 179 Comments
Create python script executable
Add in the beginning of script for python 3
#!/usr/bin/python3Add in the beginning for python 2
#!/usr/bin/pythonA linux user bob is logged into the system and possesses sudo privileges. He writes the following python script named myscript.py:
#!/usr/bin/pythonimport os print os.getenv("USER")print os.getenv("SUDO_USER")He then makes the script executable with chmod +x myscript.py and then executes his script with sudo privileges with the command:
sudo ./myscript.py
The output of that program will be (using python 2.x.x):
root bobIf bob runs the program sans sudo privileges with
./myscript.py
he will get the following output:
bob None
