0

How do I write a simple Python script that is globally executable via a simple command (such as cd or pwd)?

I know the file has to be executable and in my $PATH. I know I can omit the python prefix when calling the file by specifying the interpreter. But then I still have to call the script using the ./script syntax.

I basically want to create a bunch of Python CLI programs stored ~/bin and have them behaving the same way as Bash scripts like cd and pwd.

1 Answer 1

2

You just need to add ~/bin to your PATH. For example, you could add something like this to your ~/.bashrc file:

export PATH="$HOME/bin:$PATH"

To see the changes in the current shell, you can then do . ~/.bashrc. The path should automatically be added in all new shells that you open. You can check by doing echo "$PATH" - you should see that it starts with /home_directory/bin:....

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

1 Comment

Huh. I thought there was more to it. Thank you!

Your Answer

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