# Executing a program in Unix



## Annorax (Aug 11, 2003)

I recently got OpenBSD to install on my Vmware. I am trying to run a game from /usr/games but every game I type into the command line I get gamename: not found.

I am a Unix noob so I must be missing something simple here. Anyone know how to do this?


----------



## Squashman (Apr 4, 2003)

try* /usr/games/./gamename*


----------



## Annorax (Aug 11, 2003)

Hey that works, thank you. But why doesn't it work when I just type in the name and why does that work?


----------



## Squashman (Apr 4, 2003)

Same as in Windows. Environmental variable: PATH


----------



## Annorax (Aug 11, 2003)

Also, typing in ./ gamename works too.


----------



## Squashman (Apr 4, 2003)

Annorax said:


> Also, typing in ./ gamename works too.


Yes, if the file you are executing is in your current working directory, then yes that works as well.

If you dont want to change to the directory or type in the full path name everytime, you can set the PATH variable in your profile file. You could add /usr/games to your path variable so that you can just type the gamename from whatever directory you are in.


----------



## Annorax (Aug 11, 2003)

But I was in the /usr/games directory when I typed in the game name but it didn't work. Typing in ./ game does. It was pretty strange...


----------



## Squashman (Apr 4, 2003)

PATH is everything. In a nix environment it searches for the command you are executing in the PATH. If it is not in the path it does not execute.


----------



## codejockey (Feb 11, 2002)

> But I was in the /usr/games directory when I typed in the game name but it didn't work. Typing in ./ game does. It was pretty strange...


This only means that "." (the current directory) was not in your PATH. By default, "." is not included in root's PATH, since this represents a security hole. So, if you were root and attempted to execute a program (game, whatever) in the current directory, you likely would receive a "not found" message. Also, if you were a normal user, but your PATH did not include ".", you would receive the same message when you tried to execute a program in the current directory. Unlike DOS, Unix/Linux does not automatically search the current directory for files to be executed. When you type "./game" you explicitly specify where the program to be executed is located, which is why it works.

Hope this helps.


----------



## AGCurry (Jun 15, 2005)

codejockey said:


> This only means that "." (the current directory) was not in your PATH. By default, "." is not included in root's PATH, since this represents a security hole.


For the superuser, this is true.

For everyone else, it's only a security hole if . is not the LAST path in the PATH. In other words,

export PATH=/bin:/usr/bin:/usr/local/bin:/usr/games:.

is fine, but

export PATH=.:/bin:/usr/bin:/usr/local/bin:/usr/games

is not.

You shouldn't be playing games as root anyway!


----------



## Annorax (Aug 11, 2003)

> Unlike DOS, Unix/Linux does not automatically search the current directory for files to be executed. When you type "./game" you explicitly specify where the program to be executed is located, which is why it works.


Ah that was my confusion. I've been using DOS for a decade and am used to being in the folder of a program to execute it. Thanks for the clarification.


----------



## codejockey (Feb 11, 2002)

You're welcome -- glad my comments were helpful.


----------

