1

Lets say I have a python script that makes an http request and prints the response code to the screen and exits.

# check_app_status.py

import requests

r = requests.get("https://someapp.com")

print r.status_code

Now i can run it by

$ python check_app_status.py
200

What do I need to set up to be able to run it like this

$ check-app
200
1
  • you have to create an entry in bash aliases Commented Sep 19, 2016 at 11:41

1 Answer 1

3

Assuming you're on a unixoid system, you just need to add a shebang line:

#!/usr/local/bin/python

import requests
...

The exact location of the python executable may vary, so you can alternatively also use the shebang line #!/usr/bin/env python, which should always work.

Then, set the executable bit (chmod +x check-app). Finally, if you want to be able to call it from any location, put it somewhere in your $PATH. I would recommend extending your $PATH with a custom directory where you put your scripts (in this case ~/bin). To do that, put this in your .bashrc (or similar):

export PATH=$PATH:$HOME/bin

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.