You are not logged in.

#1 2009-02-06 02:12:57

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 193

Execute scripts in your PWD without prepending them with "./"

To execute scripts in your PWD without prepending them with "./", add it to the end of your $PATH:

$ export PATH="$PATH:."

...and, to make it permanent, create an entry in your .bashrc:

$ echo "export PATH=\"\$PATH:.\"" >> ~/.bashrc

It won't cure cancer, I just think it's cool smile

(02/05/2009) Replaced the old title with one more descriptive.

Last edited by deltaecho (2009-02-06 03:47:41)


Dylon

Offline

#2 2009-02-06 03:21:16

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: Execute scripts in your PWD without prepending them with "./"

As a (not-so-closet) paranoid, I feel it necessary to mention that, while maybe somewhat convenient, this is a potential security risk.  If you're in a directory where somebody else has write permissions, you could end up running a program of their choosing which (especially if you're root) could have disastrous consequences.  There are some people who consider adding "." to PATH tantamount to heresy.  I am nearly in that camp.  Caveat emptor.  Know what you're doing, and what the risks are.  And have fun.

Offline

#3 2009-02-06 03:31:16

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 193

Re: Execute scripts in your PWD without prepending them with "./"

I thought about that, and wondered how others felt.  By placing "." at the end of the $PATH variable, I decided there was much less of a chance of unintentionally executing any script or executable file in your current directory, because any executable -- with the same name -- in your $PATH listed before it would get 1st priority (in such a situation you would HAVE to type ./<scriptname> to run it).  As such, if I decide to keep my $PATH as it is, do you think my security could still potentially be compromised?


Dylon

Offline

#4 2009-02-06 08:32:28

Arkane
Member
From: Switzerland
Registered: 2008-02-18
Posts: 263

Re: Execute scripts in your PWD without prepending them with "./"

I'd say there still is a risk, because many applications will test for the presence of a helper application simply by trying to call it (for example with -v) and seeing if the command is found. Of course that's arguably bad practice on their part, but it's still pretty common in simpler scripts (I think).

Besides, I must say I like to keep a distinction between static executables called through my path and local, context-dependent ones needing "./". JIt just feels cleaner somehow.

Last edited by Arkane (2009-02-06 08:34:35)


What does not kill you will hurt a lot.

Offline

#5 2009-02-06 09:01:12

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Execute scripts in your PWD without prepending them with "./"

I have ~/bin in my path, so anything that I need to run regularly goes in there. For ad-hoc stuff, I can live with ./foo.

Offline

#6 2009-02-06 10:12:47

ndlarsen
Member
From: Denmark
Registered: 2005-11-02
Posts: 157

Re: Execute scripts in your PWD without prepending them with "./"

tomk wrote:

I have ~/bin in my path, so anything that I need to run regularly goes in there. For ad-hoc stuff, I can live with ./foo.

+1
Just as convenient and less risky imo.


I made it long
as I lacked the time to make it short...

Offline

#7 2009-02-06 11:18:44

Pox
Member
From: Melbourne, AU
Registered: 2007-10-04
Posts: 66

Re: Execute scripts in your PWD without prepending them with "./"

Yeah, ditto on ~/bin being a good solution - if I need to reuse it often, I'll put it (or symlink it) there.  I find the two extra characters worth the security.

Offline

#8 2009-02-06 11:20:14

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Execute scripts in your PWD without prepending them with "./"

I kept my scripts in /usr/local/bin but now I've moved them all to ~/.bin


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#9 2009-02-06 12:57:23

dolby
Member
From: 1992
Registered: 2006-08-08
Posts: 1,581

Re: Execute scripts in your PWD without prepending them with "./"

tomk wrote:

I have ~/bin in my path, so anything that I need to run regularly goes in there

+2


There shouldn't be any reason to learn more editor types than emacs or vi -- mg (1)
[You learn that sarcasm does not often work well in international forums.  That is why we avoid it. -- ewaller (arch linux forum moderator)

Offline

#10 2009-02-06 18:12:29

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 193

Re: Execute scripts in your PWD without prepending them with "./"

I put all my scripts-in-progress in ~/Workspace/Development/Scripts, and move them to /usr/local/bin when they become "production ready," but every now and then, I create a semi-random folder in which I create a script I only need temporarily; it's nice to be able to quickly create a script and run it with only its name, despite the fact prepending it with "./" only adds 2 more characters.

Arkane wrote:

I'd say there still is a risk, because many applications will test for the presence of a helper application simply by trying to call it (for example with -v) and seeing if the command is found. Of course that's arguably bad practice on their part, but it's still pretty common in simpler scripts (I think).

@Arkane, could you give me some examples?


Dylon

Offline

#11 2009-02-06 18:15:18

u_no_hu
Member
Registered: 2008-06-15
Posts: 453

Re: Execute scripts in your PWD without prepending them with "./"

deltaecho wrote:

but every now and then, I create a semi-random folder

what is a semi-random folder?


Don't be a HELP VAMPIRE. Please search before you ask.

Subscribe to The Arch Daily News.

Offline

#12 2009-02-06 18:31:35

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 193

Re: Execute scripts in your PWD without prepending them with "./"

"Semi-random" as in I decide I need to create a script and "mkdir $SOME_RANDOM_NAME_FROM_THE_TOP_OF_MY_HEAD," whether that be "temp," or "<scriptname>-dir," or whatever else.


Dylon

Offline

Board footer

Powered by FluxBB