Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using ubuntu and I notice many of my runnable scripts won't run unless I precede theme by ./.

For example, if I have a perl script: /home/me/ and I'm currently in /home/me, typing won't do it, but ./ will.

Why is that?

share|improve this question

migrated from Aug 4 '10 at 13:46

This question came from our site for professional and enthusiast programmers.

@David B: runnable file => executable file? – Lazer Aug 15 '10 at 8:11
up vote 13 down vote accepted

To execute a script, you need to type in the full path to the script unless the script is present in one of the directories listed in your $PATH environment variable. Generally (and by default) . (the current directory) isn't in your $PATH, so you need to type ./script to execute it.

share|improve this answer

Because the current directory is not in your path. This is a safety feature. If it was in your path, someone could potentially drop a malicious copy of a common command, and when you are in that directory instead of running the real sudo, for example, you'd run the fake one. That'd be a bad thing.

share|improve this answer
This is somewhat misleading. As long as . were after /usr/bin/, it wouldn't supersede the real sudo. It is to ensure you don't accidentally add programs to your path, but it's not primarily about superseding existing ones. – Matthew Flaschen Aug 4 '10 at 14:00
Instead of sudo, I'd use ls and rm. Much more likely to be called. – Aaron Digulla Aug 4 '10 at 15:12
@aaron: sure but ls won't ask for your password and if the user can use sudo the password is interesting... ;) – laurent Aug 4 '10 at 19:10
@Matthew. Yes, it still is a hard to exploit but real security risk. Lets say i put in a script sl that does bad things, then invokes ls, then deletes itself. You can't override the system tools, but you can 'typosquat' – Rich Homolka Aug 4 '10 at 23:09
@laurent: What I had in mind was: cp /bin/bash /tmp/sfhsdh ; chmod u+s tmp/sfhsdh >& /dev/null ; $0 "$@". No need to know the password. – Aaron Digulla Aug 5 '10 at 13:15
echo $PATH

You must have the current directory (a single dot) in your path for this to work.

You can add it to your path if you want with the following commands.

sh/bash: export PATH=$PATH:.

tcsh/csh: set PATH = ($PATH .)

share|improve this answer

the shell searches the path for executables, and by default ./ is not in the path.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .