Basics of running Python scripts from bash shell

Download a nice free open software called ATOM, create a file called text.py

from __future__ import absolute_import, division, print_function

print (‘hello’)

Navigate to the directory that you just created and try to python script:

[delanajero@DELAN Documents]$ python text.py

hello

If you want to run just the script without typing python before the file perform the following:

[delanajero@DELAN Documents]$ chmod +x text.py

  • make sure that the file is executable by adding execute to the file than just read and write.

to verify:

[delanajero@DELAN Documents]$ ls -l

total 4

-rwxrwxr-x. 1 delanajero delanajero 82 Jul 22 21:40 text.py

Include the following command so python would know where to locate the command as a python script:

[delanajero@DELAN Documents]$ PATH=”$(pwd):$PATH”

Add the following to your python script:

#!/usr/bin/env python

Verify:

[delanajero@DELAN Documents]$ text.py

hello

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s