Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2054  / 2 Years ago, mon, january 3, 2022, 9:45:56

When I try to run a python file, say hello.py, it prompts



bash: ./hello.py: Permission denied


so I need to



chmod u+x hello.py


before I run it.



Is it possible to automatically grant access to all python file as soon as they are created?


More From » permissions

 Answers
3

You can use a simple script like this,



#!/bin/bash

if [ $# -lt 2 ]
then
chmod +x $(pwd)/$1
$(pwd)/$1
else
chmod +x $(pwd)/$1
$(pwd)/$1 $2
fi


Save the above script as runpy.sh, keep it in PATH (you can keep it in ~/bin)



Give it execution permission from terminal,



chmod +x ~/bin/runpy.sh


Usage




  • To run hello.py without changing its permission run in terminal,



runpy.sh hello.py



  • In case if you want to use anything at the argument of the python program, give the arguments inside " " like,



runpy.sh hello.py "-option arg1 arg2 agr3"


It should do the trick. But don't forget to use the shebang line in python (.py) file,



#!/usr/bin/python

[#27963] Wednesday, January 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
panshow

Total Points: 454
Total Questions: 98
Total Answers: 122

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
;