LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Create terminal command to run program ? (http://www.linuxquestions.org/questions/linux-software-2/create-terminal-command-to-run-program-4175455460/)

steak1987 03-25-2013 02:14 AM

Create terminal command to run program ?
 
Im running linux mint 14 XFCE off of a persistent flashdisk, and I like running the newest stable version of firefox. I downloaded it and extracted it, and then moved the folder (which I named firefox19) to /opt/ ...

It runs fine if I double click it, but I was wondering, how do I make the program run using a simple terminal command ?

How can I get firefox to run from that location, using a terminal command like 'firefox19' instead of having to navigate to that directory?

yooy 03-25-2013 02:22 AM

if you doubleclick firefox icon to run it, than it looks something like "exo-open /opt/firefox" or "sh /opt/firefox".

just enter into terminal "sh " or "exo-open " and drag and drop file you are opening and it should work. Add "&" at the end of command to run it in background.

pan64 03-25-2013 02:22 AM

There are a lot of ways to do that:
you can have alias
you can costruct a function
you can make a script in your bin dir to invoke that app
you can add the location to your PATH
you can create a symbolic link from /usr/bin (or /usr/local/bin or whatever) to your app
you can create a shortcut on your desktop

...

TobiSGD 03-25-2013 10:42 AM

Mint 14 is based on Ubuntu 12.10, which already comes with Firefox 19, so if you have an up-to-date system all this shouldn't be necessary in the first place.

steak1987 03-25-2013 12:09 PM

What i meant is, how can i turn an executable file to a direct terminal command?


Im fairly new to linux and I've heard of symbolic links, but ive also heard that things can go wrong if I dont use them properly.

Quote:

Originally Posted by TobiSGD (Post 4918441)
Mint 14 is based on Ubuntu 12.10, which already comes with Firefox 19, so if you have an up-to-date system all this shouldn't be necessary in the first place.


Thats true, but I also want to be able to use this for other programs and executables.

TobiSGD 03-25-2013 12:23 PM

If you have an executable, for example /opt/firefox/firefox, you have these possibilities to access it:
1. Use the full path to start the application:
Code:

/opt/firefox/firefox
This is of course a little bit long-winded if you have to do it every time.
2. Add the applications path to your PATH variable in your .bashrc:
Code:

PATH=$PATH:/opt/firefox
or
Code:

PATH=/opt/firefox:$PATH
Which one of those you use is critical if you have more than one application with the same name in different locations. In the second case the application in /opt/firefox will always be executed, because that path is the first searched in, in the first case it is vice-versa.
3. Use a symlink, for example with
Code:

ln -s /opt/firefox/firefox /usr/bin/firefox-opt
Notice that I have used the name firefox-opt for the symlink, just for the case that a binary named firefox is already in place there. Also, you must have root privileges to create the symlink.
4. Create an alias in your .bashrc:
Code:

alias firefox-opt='/opt/firefox/firefox'
Now you can just use firefox-opt as normal command.
5 Create a script that starts the binary in /opt/firefox for you, like this one
Code:

#!/bin/sh
/opt/firefox/firefox

Then make it executable and place it under a name you like in the PATH, for example in /usr/bin or /usr/local/bin.

Which one you choose is up to you, but as stated before, in the case of Firefox this shouldn't be necessary at all if your system is up-to-date.

steak1987 03-26-2013 03:47 AM

Quote:

Originally Posted by TobiSGD (Post 4918535)
If you have an executable, for example /opt/firefox/firefox, you have these possibilities to access it:
1. Use the full path to start the application:
Code:

/opt/firefox/firefox
This is of course a little bit long-winded if you have to do it every time.
2. Add the applications path to your PATH variable in your .bashrc:
Code:

PATH=$PATH:/opt/firefox
or
Code:

PATH=/opt/firefox:$PATH
Which one of those you use is critical if you have more than one application with the same name in different locations. In the second case the application in /opt/firefox will always be executed, because that path is the first searched in, in the first case it is vice-versa.
3. Use a symlink, for example with
Code:

ln -s /opt/firefox/firefox /usr/bin/firefox-opt
Notice that I have used the name firefox-opt for the symlink, just for the case that a binary named firefox is already in place there. Also, you must have root privileges to create the symlink.
4. Create an alias in your .bashrc:
Code:

alias firefox-opt='/opt/firefox/firefox'
Now you can just use firefox-opt as normal command.
5 Create a script that starts the binary in /opt/firefox for you, like this one
Code:

#!/bin/sh
/opt/firefox/firefox

Then make it executable and place it under a name you like in the PATH, for example in /usr/bin or /usr/local/bin.

Which one you choose is up to you, but as stated before, in the case of Firefox this shouldn't be necessary at all if your system is up-to-date.


Where would I find the .bashrc file ? I cant find it in my home directory, even after showing all hidden files.

TobiSGD 03-26-2013 04:55 AM

If it doesn't exist just create it, many distros don't create it by default.

steak1987 03-26-2013 06:07 AM

Quote:

Originally Posted by TobiSGD (Post 4919055)
If it doesn't exist just create it, many distros don't create it by default.

Thanks, tip 4 worked perfectly.

TobiSGD 03-26-2013 06:10 AM

I am still interested why this is necessary for you, since a fully updated Mint 14 should already have the latest Firefox.

steak1987 03-26-2013 06:32 AM

Quote:

Originally Posted by TobiSGD (Post 4919096)
I am still interested why this is necessary for you, since a fully updated Mint 14 should already have the latest Firefox.

I wanted to learn the methodology so I could use it for other programs and applications that I may want to set up to run easily.

For example Minecraft, certain games, and other small executables that may be of use to me.

TobiSGD 03-26-2013 08:22 AM

Ah, OK. Anyways, if the answer is sufficient for you please mark this thread as solved using the thread tools at the top of the thread.

steak1987 03-26-2013 11:42 AM

Again, thanks for everybodys help


All times are GMT -5. The time now is 03:04 PM.