How to create command to start a program without going to that folder?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to create command to start a program without going to that folder?
I know this should be a simple thing to do, but I've searched around, and haven't found the way to do it- partially because I'm not sure what to call it.
I want to create a command that will start a program. I want to be able to open the program with this command regardless of whether I am working in the directory where the program is located or not. Also, is there a name for doing this?
I've adjusted my .bash_profile file to include in my $PATH the directory where the program is located, but it still is not working, and I'm not sure what else to try.
Thanks for your help!!!
janestclaire
Last edited by janestclaire; 08-31-2005 at 12:14 PM.
I think I know what you mean. I don't know a specific name for it. For my example I'll use doom legacy, because that has a similar issue. If I type from my home directory:
/mnt/Programs/doom/lsdldoom -iwad doom.wad
It won't work because I have to be in the /mnt/Programs/doom directory for lsdldoom to find the iwad. I could also provide the path to the iwad in the same command but that can become a long command to type and that's more possibility to make typos.
I would create a script like this:
#!/bin/bash
cd /mnt/Programs/doom
lsdldoom -iwad doom.wad
cd ~
and save it in my ~ directory. Don't forget to make it executable.
Thanks Dracolich- that worked! (at least it seems to be working)
Is this a "shell script"? Also, you said to make sure it is executable. I'm not sure how, but I took the example you gave, modified it for my program, and made the file using vi editor. Then I just saved it into my home directory. When I typed the name of the vi file into the command line it opened my program.
But, I didn't do anything special to make it executable-- can you explain this a little more?
Yeah, I know about the semicolons. That just makes the script two lines instead of four.
This qualifies as a shell script - a script file that executes a series of shell commands.
Maybe RH does some things automagically that Slackware doesn't. If you type
ls -l <filename>
for your script file what permissions do you see? (e.g. -rwxrwxr--) X's indicate execute permission. When I make a script I have to use 'chmod +x filename' to add the execute permission before it'll run.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.