Thursday, May 9, 2024
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 16901  / 3 Years ago, wed, june 9, 2021, 12:04:27

I'm new to the Linux environment and I noticed there are many programs of which we can use only the program name to start them in the Linux terminal.



E.g. gedit, vi, firefox



Instead of providing all of the program's path, I would like to run my own programs like this in the terminal by only typing the program name. Programs I like to run are written in Java and Python and script files (.jar, .pyc, .py and .class)



How should I proceed?


More From » command-line

 Answers
6

Let's say you want to execute a file called fun.py located on your Desktop using the command funny. Obviously, you'll need python for that, so the exact bash command would be python ~/Desktop/fun.py.



How to do that without having to change the PATH variable:



First create a file called funny with the following contents:



#! /bin/sh
python ~/Desktop/fun.py


and save it to a folder (let's say you have saved it on your Desktop folder).



If non-existent, create a folder named bin in your home directory.
Then execute the following commands from a terminal:



source .profile
chmod +x ~/Desktop/funny
mv ~/Desktop/funny ~/bin


You can now enter the command funny to execute the python script.


[#21448] Wednesday, June 9, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gigglcept

Total Points: 113
Total Questions: 105
Total Answers: 125

Location: Christmas Island
Member since Wed, Jan 13, 2021
3 Years ago
gigglcept questions
Mon, Jul 5, 21, 19:38, 3 Years ago
Thu, May 27, 21, 13:35, 3 Years ago
Tue, Feb 8, 22, 09:59, 2 Years ago
Fri, Dec 16, 22, 12:32, 1 Year ago
;