Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop driver drivers dvd email error excel firefox hard drive hardware internet keyboard laptop malware monitor motherboard network networking outlook problem processor ram recovery router safe mode screen slow sound spyware tdlwsp.dll trojan upgrade video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Executing a program in Unix

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
Annorax's Avatar
Senior Member with 279 posts.
 
Join Date: Aug 2003
Location: Westfield, MA
Experience: Intermediate
02-Aug-2005, 09:05 PM #1
Executing a program in Unix
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?
__________________
My Computer:
==========
Windows XP Professional w/SP2 on 300gig HD
AMD Athlon XP 1600 w/512 MB PC133 SDRAM
Hercules Kyro2 w/64 MB RAM
80gig 7200rpm HD & 20gig 5400rpm HD slaves
TDK 40x CD-RW
SoundBlaster Live 5.1
Squashman's Avatar
Distinguished Member with 14,984 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
02-Aug-2005, 09:30 PM #2
try /usr/games/./gamename
Annorax's Avatar
Senior Member with 279 posts.
 
Join Date: Aug 2003
Location: Westfield, MA
Experience: Intermediate
02-Aug-2005, 09:47 PM #3
Hey that works, thank you. But why doesn't it work when I just type in the name and why does that work?
Squashman's Avatar
Distinguished Member with 14,984 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
02-Aug-2005, 09:54 PM #4
Same as in Windows. Environmental variable: PATH
Annorax's Avatar
Senior Member with 279 posts.
 
Join Date: Aug 2003
Location: Westfield, MA
Experience: Intermediate
02-Aug-2005, 10:06 PM #5
Also, typing in ./ gamename works too.
Squashman's Avatar
Distinguished Member with 14,984 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
02-Aug-2005, 10:13 PM #6
Quote:
Originally Posted by Annorax
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.
__________________
I hate asking the same question twice!
How to ask questions the smart way!
Microsoft MVP - User Desktop Experience
Annorax's Avatar
Senior Member with 279 posts.
 
Join Date: Aug 2003
Location: Westfield, MA
Experience: Intermediate
02-Aug-2005, 10:22 PM #7
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's Avatar
Distinguished Member with 14,984 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: IIAHYAYCESA,YAADA!
02-Aug-2005, 11:04 PM #8
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's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
02-Aug-2005, 11:41 PM #9
Quote:
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.
__________________
The slowest component still sits at the keyboard.
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
03-Aug-2005, 09:58 AM #10
Quote:
Originally Posted by codejockey
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!

Last edited by AGCurry : 03-Aug-2005 12:24 PM.
Annorax's Avatar
Senior Member with 279 posts.
 
Join Date: Aug 2003
Location: Westfield, MA
Experience: Intermediate
03-Aug-2005, 06:40 PM #11
Quote:
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's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
04-Aug-2005, 12:17 AM #12
You're welcome -- glad my comments were helpful.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 05:46 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.