LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 03-05-2005, 01:12 AM   #1
ToothlessRebel
Member
 
Registered: Jun 2004
Location: FL, USA
Distribution: Slackware 9.1
Posts: 190

Rep: Reputation: 30
Run a command from anywhere


I have a script saved, but I don't want to have to change my working directory to where it is everytime I want to use it. Is there somewhere I can save a link or edit a list to make this work from any directory? Using Slack 9.1 and primarily the BASH shell.
 
Old 03-05-2005, 01:21 AM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 64
I'm not sure if I understood the question, but you can create a link with "ln -s /whatever.your.program.is /usr/bin/program.name" and it should run from everywhere (?).

Good luck!
 
Old 03-05-2005, 01:35 AM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
From anywhere in the system, all you need to do is enter the full path to the executable file. For example. Let's say I open a term window and I'm in my home directory. I want to run an app in /sbin. I could cd to /sbin. Or, I could give the command, from my home directory: /sbin/<command-name>, where <command-name> is the name of the command I want to run, and it will run.
Basic rule:
If you are in the directory in which the executable is located: use ./<command>. The ./ tells the shell that the executable is in the current working directory.
Otherwise, from anywhere in the system, give the full path to the executable, and it will run.
 
Old 03-05-2005, 02:32 AM   #4
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
You should look into the $PATH variable. Take a look at this article.
 
Old 03-05-2005, 02:36 AM   #5
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Ubuntu, FreeBSD
Posts: 1,449

Rep: Reputation: 48
lol, I'm going to give the third different solution to this problem.

# Create a binary directory for your own scripts. This is common in almost
# all unix systems and is about the only way to easily get it working when
# you don't have root access (and it is a good idea anyway to keep user
# scripts away from the system utilities).
mkdir ~/bin
mv /path/to/script ~bin/

# Check your path and make sure $HOME/bin is in it. On most systems,
# this is the case (as this solution is so common that most systems are
# setup expecting users to add programs to $HOME/bin).
echo $PATH

# If it isn't run:
PATH=$PATH:$HOME/bin; export PATH

And remember to add it to .profile where your path is listed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command to run another command against a list of files psweetma Linux - General 3 11-09-2005 06:29 PM
Cannot run CP command! hrudolph Linux - Newbie 12 05-14-2005 11:52 PM
How to run a command Maintech Mandriva 1 11-20-2004 10:41 PM
the command for run command devfreak Linux - Software 4 06-08-2004 11:24 AM
Run Command csosa Linux - Software 1 09-27-2003 11:41 AM


All times are GMT -5. The time now is 02:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration