2

I'm new to python programming. I want to create an alias to my script, so that i can use it in the terminal.

I've a .py file named r.py and i'm trying to create an alias for it. I created it by using the following commnad:

$ alias new="python /Python_scripts/radians.py"

Now when i type the word new in the terminal it's giving an error -'no such file exists'

Can anyone tell me how to do it?

2
  • 2
    Is your path correct? Are you trying to use an 'absolute path' or a 'relative path'? You can run 'readlink -m radians.py' to get the absolute path to your python script and then update your alias with that instead. Commented Aug 1, 2014 at 5:49
  • In bash syntax no space is allowed around =. Commented Aug 1, 2014 at 5:53

1 Answer 1

2

The path is probably not correct:

alias new="python /Python_scripts/radians.py"

will try to find the Python_scripts directory at the root level while I assume it would be in your home directory. Try replacing it with a relative path

alias new="python Python_scripts/radians.py"

or, better, with

alias new="python ~/Python_scripts/radians.py"

so that you can run the aliased command from anywhere.

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

2 Comments

$HOME is preferred over ~ for portability.
@BurhanKhalid How so? ~ is also defined by the POSIX standard to refer to the current user's home directory. True, there are situations where you cannot use ~, but this is not one of them, and that's a matter of correctness, not portability.

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.