LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 04-20-2005, 02:22 PM   #1
bbohl
LQ Newbie
 
Registered: Apr 2005
Posts: 2

Rep: Reputation: 0
Question about running programs with ./


Hello, new to Linux so Pardon My Ignorance.....

I've noticed that some programs aren't "found" when I run them, unless I run them like this:

$ ./myprogram

For example, if I have a program in /usr/programs/myprogram, and I do this:

$ cd /usr/programs
$ myprogram

It gives me an error that it can't find myprogram.
But if I run it like this:

$ cd /usr/programs
$ ./myprogram

It runs. This only seems to happen with some programs. Anyone know why this is?
 
Old 04-20-2005, 02:30 PM   #2
kencaz
Senior Member
 
Registered: Mar 2005
Location: Las Vegas, NV
Distribution: Mandriva Slackware FreeBSD
Posts: 1,468

Rep: Reputation: 48
It is a script file. ./myprogram

try
cat ./myprogram
to see script contents.

http://www.freeos.com/guides/lsst/

KC
 
Old 04-20-2005, 02:51 PM   #3
coldsalmon
Member
 
Registered: Mar 2005
Location: USA
Distribution: Kubuntu Breezy
Posts: 79

Rep: Reputation: 15
Yes, the way Linux manages executables is much different than in MS-DOS (I'm assuming that this is where you're coming from). In Linux, you can only execute commands that are in certain directories, such as /bin, /sbin, /usr/bin. These directories are contained in the PATH variable. You can see this list by typing:

$ echo $PATH

This makes it very easy to execute commands from wherever you are in the directory tree without having to cd to the directory that contains the executable, or having to type out the whole path name. If you want to execute a command that is not in one of these designated directories, you have to type the absolute path name (eg /usr/program/myprogram or ./myprogram, if you are in /usr/program already). While this might seem like an inconvenience, it prevents you from accidentally executing files in the current directory when you really wanted to execute a generic system command. For example, it prevents someone from creating a trojan named "ls" which would be run whenever you wanted to use the ls command. It also prevents commands from behaving differently depending on which directory you are in.

Hope that helps,

--C
 
Old 04-20-2005, 04:37 PM   #4
bbohl
LQ Newbie
 
Registered: Apr 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks so much for the answer! I've been reading about Symbolic Links, which is another new topic that seems related.
For example, when I installed firefox I put it in /usr/firefox. To run the firefox program, rather than adjusting the PATH variable to add /usr/firefox or having to cd /usr/firefox and then run ./firefox, I could create a symbolic link in /usr/bin for firefox?
 
Old 04-20-2005, 06:16 PM   #5
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,893

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
You could edit your user .bashrc or .bashrc_profile (different distros have different names for it) to add an alias. Such as: alias firefox="/usr/firefox". Then, everytime you boot up, the command is available to you by simply typing firefox and pressing enter.
To make such an alias available to all users, edit the /etc/bashrc to add the alias there. Be adivsed that, on upgrading your distro, the system bashrc may be overwritten, in which case you could loose all of your aliases. In other words, keep a backup copy, which you can then cut and paste your aliases into a changed bashrc.
 
Old 04-20-2005, 07:13 PM   #6
IBall
Senior Member
 
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
You can always change your PATH variable though. For example, if you wanted to have a bin directory in your home, you would add the following line to .bash_profile:
Code:
export PATH=$PATH:/home/iball/bin
If you want to be able to execute programs in the current directory, (NOT generally a good idea, ,particularly for root), add the following line to .bash_profile
Code:
export PATH=$PATH:.
I hope this helps
--Ian
 
  


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
Running Programs Slayer097 Linux - Newbie 3 02-23-2005 04:43 PM
Question about installing and running programs BRoscoL Linux - Newbie 6 05-24-2004 01:56 PM
Choppy sound when other programs running + mouse and login question (tm) Linux - Newbie 6 03-24-2004 09:57 AM
Running programs? BajaNick Linux - General 10 07-07-2003 09:56 PM
Help on Running Programs mooreted Linux - Software 3 05-16-2003 10:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:07 PM.

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