Sam
Sam

Reputation: 974

How to execute a program by name on command-line without typing current directory?

On my last UNIX setup, I was able to simply type a binary's name if I was in the same directory and it would execute it. However on this new setup, I have to preface binary names with ./ if I want to execute them. Anyone know how to circumvent this?

Thanks.

Upvotes: 2

Views: 216

Answers (2)

Mike
Mike

Reputation: 8973

I'm guessing you are using the default shell and that the shell is bash.

Edit: /etc/bashrc and add this:

export set PATH=$PATH:.

Upvotes: 1

Trott
Trott

Reputation: 70183

The conventional way to address this (and probably the way it was done on your previous setup) is to add . to your PATH environment variable. So if your PATH is /usr/bin:/bin, then add . to the end (along with the : separator) so you have /usr/bin:/bin:.. Exactly how to do that varies by shell. A quick Google will no doubt get you the answer for your shell.

Do be aware that there are potential negative security implications to that, though, especially on a shared service. If an attacker manages to get an evil file in a directory where you are, and to name that file a normally-innocuous command (like ls), they could cause you to unintentionally run the evil file.

For this reason, if you are going to do this, at least make sure you put . as the last item in your PATH.

Upvotes: 2

Related Questions