LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-18-2007, 07:43 AM   #16
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985

I'd just like to point out the vast vast difference between "can" and "should"...
 
Old 06-18-2007, 08:10 AM   #17
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548

Rep: Reputation: 33
As has been said, it is very easy to change your $PATH so that the current dir is included in your PATH. It is not a good idea because of the security issue you said you understand. If you understand the reasoning and the security issue, and you understand that the default ./ can be changed so that it is not needed, there you have it. All the flexibility possible. Have it your way, so to speak.
 
Old 06-18-2007, 08:14 AM   #18
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by acid_kewpie
I'd just like to point out the vast vast difference between "can" and "should"...
Well spoken...
You CAN set up a Linux system to be incomprehensible to anyone but you.
If you do this, you SHOULD not expect mere mortals to help you
 
Old 06-18-2007, 01:55 PM   #19
dickgregory
Member
 
Registered: Oct 2002
Location: Houston
Distribution: Arch, PCLinuxOS, Mint
Posts: 257

Rep: Reputation: 34
Here is an example of why it can be a bad idea to have ./ in your implicit path, especially if you are running as root.

Say someone creates a script that does a "rm -r /" command, and they name the script "ls". As root you navigate to their home directory, or wherever this command is, and you type "ls" to see what is in the directory. You will get their script instead of the real ls, and will wipe out your computer.

There are usually very good reasons we do things the way we do in Linux, even through they may not be apparent to someone coming from Windows.

PS. The above scenario is another reason you should not run as root unless you need to and know exactly what you are trying to do.
 
Old 06-18-2007, 02:04 PM   #20
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,249
Blog Entries: 5

Rep: Reputation: 191Reputation: 191
If you install a program into a non-standard directory, you can always create a symlink to the executable, and put the link in a directory that is already in your PATH, someplace like /usr/bin maybe.

Why consider adding all sorts of strange directories to your path when a simple link to the executable placed in the right location can resolve the issue ?

Outside of that ./ is a small penalty to pay for a one off execution of a program. 2 measly keystrokes..
 
Old 06-18-2007, 03:14 PM   #21
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Quote:
Originally Posted by benchmarkman
So I am new to Linux and a co-worker and I were discussing using ./ so that Linux knows to look in the current directory. My co-worker explained that you must use ./ to take away ambiguity and that is a better method than Windows. I feel this is pretty stupid because Linux should assume if I have navigated to a directory that it should know that I want to execute the file that is in that directory. Is there another reason for this? If not can you give me a good reason why I should have to use ./ ? What are your thoughts on this?
You don't have to use ./. Just add it to your PATH variable. Probably won't be too risky for the unprivileged user, just wouldn't recommend adding ./ to the privileged user's PATH. It's really not much different than DOS/Windows? There's a %PATH% variable in the Microsoft world as well it just includes ./ (if you will) by default.

It's a convention that has been used for 30 odd years for security reasons. Make sure you understand the potential consequences before you add it. That's the thing about security...it's a pain in the a** and if it works you'll never even know it. If you choose not to use it, it'll be too late before you know it. Keep in mind that spyware, adware, malware, and virii don't ask permission before infecting a Windows machine precisely because MS users generally choose not to use security.

Finally, just because you are 'in' a directory doesn't mean you want to execute a file in that directory. Maybe you navigated to that directory to execute system commands on files in that directory otherwise you would need to pass the full path to the command.
 
Old 06-18-2007, 03:43 PM   #22
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
This is somewhat off-topic, but the ./ syntax is not limited to addressing files in your current directory. For example, I keep my shell scripts in a sub-directory of ~/ called (unimaginatively) Scripts. So, for example, to run my script that mounts the Logical Volumes on my USB drive, I need to run the MountUsb script, and a ./Scripts/MountUsb does the trick.

Note that the actual characters I need to type are ./Sc<tab>M<tab>U<tab>, so it goes fairly fast.
 
Old 06-18-2007, 05:00 PM   #23
Lux Perpetua
LQ Newbie
 
Registered: Aug 2005
Location: Local Group
Distribution: Ubuntu Linux
Posts: 15

Rep: Reputation: 0
Quote:
Originally Posted by weibullguy
Finally, just because you are 'in' a directory doesn't mean you want to execute a file in that directory. Maybe you navigated to that directory to execute system commands on files in that directory otherwise you would need to pass the full path to the command.
I think this is the primary issue behind the OP. The confusion is around the fact that most directories contain data files, not programs. There are just a few directories intended to store programs, and those directories should be in the PATH, making it unnecessary to think about those directories at all.
 
Old 06-18-2007, 05:20 PM   #24
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Quote:
Originally Posted by PTrenholme
...So, for example, to run my script that mounts the Logical Volumes on my USB drive, I need to run the MountUsb script, and a ./Scripts/MountUsb does the trick...
In that case, Scripts/MountUsb would suffice - the './' is unnecessary. And, as I said, I put my personal bin directory on my path so that MountUsb would suffice. But any way just as long as the bleeping thing executes, eh?
 
Old 06-18-2007, 07:18 PM   #25
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by digiot
In that case, Scripts/MountUsb would suffice - the './' is unnecessary. And, as I said, I put my personal bin directory on my path so that MountUsb would suffice. <snip>
Yes, but tab compleation for commands only works for things in $PATH, so the reduced keystroke version only works with the ./ prefix.
 
Old 06-18-2007, 08:48 PM   #26
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Ah, true.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to untar a file in another directory other then current directory. dr_zayus69 Linux - Software 8 05-16-2007 11:01 AM
bash scripting help want to execute external function on current item. Benanzo Linux - Software 3 02-03-2007 02:45 PM
[SOLVED] Installind Slamd64-current. "cannot execute binary file" message about installpkg BrutalMusic Slackware - Installation 1 05-11-2006 09:35 AM
no such file or directory exists when trying to execute a exe ryedawg Linux - Software 5 12-05-2005 05:42 AM
"Cannot execute KDE: No such file or directory" abboq Linux - Software 1 09-27-2003 08:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:16 AM.

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
Open Source Consulting | Domain Registration