Create your own commands and run in linux terminal using python


Using python you can create your own commands and run it using linux terminal. The steps are : -

1. Create a simple pragram like hello world . with the location of the python interpretor .

(For eg) : #!/usr/bin/python
# Filename : myfirstprogram.py
print "This is my FirstProgram !"

here # - is used as comment

And the line follwed with the symbols #! - is known as shebang line , This is used to tell the linux system that this program should run with that interpretor at the destination.

Now give the excecute permission using:

$ chmod a+x myfirstprogram.py

then run using

$./myfristprogram.py

o/p : This is my FirstProgram !

Then rename this program as myfirstprogram and it will still run when you excecute using terminal.

Now give the command $ echo $ path
/home/usr/bin:

you will get the location of the environment variable.
Now paste the program file in that location. And run the myfirstprogram in terminal it will run. You can now run this program from any location

2 comments:


  1. Thanks for providing good information,Thanks for your sharingpython Online Training

    ReplyDelete
  2. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles.

    Digital Marketing Training in Chennai

    Digital Marketing Course in Chennai

    ReplyDelete