LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training 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 07-13-2011, 12:31 AM   #1
marksimmonds
LQ Newbie
 
Registered: Oct 2010
Location: melbourne australia
Posts: 4

Rep: Reputation: 0
using ./ to run programs


Hi,

I have seen other users run programs by putting a ./ in front of them....

eg.


$ ./newprog.sh

and just running
$ newprog.sh
does not work.

what is the ./ doing?

thanks!
 
Old 07-13-2011, 12:33 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
For safety reasons some distro's don't put the current working dir (the ".")
in users PATH. In those you need to use ./program to "qualify" a relative
path to the executable.


Cheers,
Tink
 
1 members found this post helpful.
Old 07-13-2011, 12:36 AM   #3
salparadise
Senior Member
 
Registered: Nov 2002
Location: Birmingham UK
Distribution: Various
Posts: 1,736

Rep: Reputation: 146Reputation: 146
It's a way of telling the system that the program to run is in the current working directory.

So, if I type 'firefox' om its own the system will look on the various "paths" (locations of executable files) and run firefox where it finds it (usually symlinked to /usr/bin).
But, if I downloaded an updated version of firefox and had extracted the files from the bz2 file, how would I tell the system to run that version of firefox and not the installed version?
Answer - by typing "./firefox" - the ./ says "in this folder only".
 
Old 07-13-2011, 01:27 AM   #4
kasl33
Member
 
Registered: Oct 2004
Location: USA
Distribution: Ubuntu-Server, Mac OS X, Arch Linux
Posts: 356

Rep: Reputation: 48
those replies are both right on. When it comes to a .sh file, ./file.sh will typically only run if the file is marked executable using chmod +x file.sh

a way around this is just to run a .sh file this way:

sh file.sh
 
1 members found this post helpful.
Old 07-13-2011, 02:21 AM   #5
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
I'll add some salt to the soup: the dot is a reference to the current directory, the same way two dots (..) is a reference to the parent directory (the directory in which the current directory is in). If you do

Code:
/bin/ls -d ./.*
in any directory (I used exact path to ls to prevent any aliases from being in effect), the first two "files" (in Unix, "everything is a file") you see are . and .., which point to the current directory, and the parent directory. This is why

Code:
cd .
seems to do nothing, because it merely would change the current working directory to the current directory (which it already is), and

Code:
cd ..
brings you one level higher in the directory tree (e.g., if you were in /home/user and issued that, your working directory would then be /home). So, just as you can execute an executable using the full path (e.g., /bin/ls), you can execute an executable by typing the path to the current directory, ./ using the dot. Typing the filename without any path does not work unless that directory happens to be in the $PATH variable, which lists the directories where the given executable is searched for, in order.

In addition, typing ./somescript.sh (if it were a shell script; or ./someperlscript.pl, or ./somepythonscript.pl, etc.) only works if the script contains information about what interpreter should be used (the first line in the script, for example #!/bin/bash). Without that line it can be run by passing it to the interpreter directly, e.g. by running for example

Code:
sh ./somescript.sh
Hope this gave you some idea of what's going on..
 
  


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
What do I need to run C++ programs ? tuxuser19 Programming 2 01-10-2006 08:48 PM
Cannot run any 3D programs zxt Linux - Distributions 0 07-21-2004 11:32 AM
how to run programs? matejj Linux - Newbie 6 05-06-2004 08:16 AM
How to run programs? timberwolf Mandriva 3 12-08-2003 09:06 AM
cant run certain programs da Perp Linux - Newbie 3 11-08-2001 07:02 PM


All times are GMT -5. The time now is 05:40 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