0

Hey guys. So, I have a Python script. Let's call it "Pythonfile.py" (Wow, I have so much imagination xD) I would usualy run it by typing in:

$ python ~/Desktop/Pythonfile.py -arg1 arg2 arg3

Now, this is kinda bothering; having to type all the python things. Idealy, I would want to run it like:

$ pythonfile -arg1 arg2 arg3

This would mean adding a new command to bash. But how? I would guess you should put a file:

/usr/bin/pythonfile

But what should be inside? I want it to run the original python script, which is located on the desktop - AND WITH THE ARGUMENTS .I'm on Ubuntu 10 by the way.

1 Answer 1

1

Don't place the command in /usr/bin unless it is meant to be run by all users. Place it in ~/bin instead, and modify the PATH environment variable to search for executables there, by adding this to yout ~/.bashrc file:

export PATH=$PATH:~/bin

As to the contents of the (now) ~/bin/pythonfile, you may use:

#!/bin/bash
python ~/Desktop/pythonfile.py $*

The first line tells bash the file is a bash script, and the second line executes the python script.

You can also set #!/usr/bin/env python as the first line of the Python script, move the script to ~/bin, make it executable, and the run it as:

$ pythonfile.py -arg1 arg2 arg3

Something I like to do with that second option is to add a symbolic link to avoid having to type the .py part:

$ cd ~/bin
$ ln -s pythonfile.py pythonfile
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.