Reputation: 8380
I have the following file:
$ cat my_exec.sh
#!/usr/bin/env python
print(10)
It should just print 10
. However, I can't get it to do so:
$ sudo ./my_exec.sh
sudo: ./my_exec.sh: command not found
$ sh my_exec.sh
my_exec.sh: line 3: syntax error near unexpected token `10'
my_exec.sh: line 3: `print(10)'
How do I run my file?
Upvotes: 1
Views: 159
Reputation: 1170
#!/usr/bin/env python
python my_exec.py
chmod +x my_exec.py
and then ./my_exec.py
Upvotes: 2
Reputation: 11
You must enter the directory that you have saved you file through the cmd with cd command. After that you just execute the file with : python name_of_the_file.py . But first you must make it executable with chmod command
For example if you have saved your file at Desktop with the name mycode.py :
cd Desktop
chmod +x mycode.py
python mycode.py
Upvotes: 0
Reputation: 126
You can run it via the python command:
$ python my_exec.sh
To run it as simply ./my_exec.sh, you need to make the file executable first:
$ chmod 755 my_exec.sh
Also note that by convention python files end in .py .
Upvotes: 2