Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Have to add ./ to executables. Why?

Status
Not open for further replies.

ag6969

Technical User
Jun 4, 2001
85
CA
It seems any programs I install must have ./ appended to the front in order to run the program/script. The files are definitely executable, and it doesn't matter which user runs them. I know there is a reason, but I don't know what it is. Is there a way to correct this so I can just type the name of the program? The path is in the .profile file (/usr/local/bin). I'm stumped!
 
You need to add other directories to your PATH variable. If all it has is [tt]/usr/local/bin[/tt], then it will only run commands in that directory without the full path typed as part of the command. Add the following lines to your [tt].profile[/tt].
[tt]
export PATH=${PATH}:/bin:/usr/bin:/usr/sbin
export PATH=${PATH}:/usr/ucb:/usr/ccs/bin
export PATH=${PATH}:.:~
[/tt]
Go ahead and add whatever directories you need, separated by colons. Some of these are Solaris dirs and you may need different ones. I'm also assuming a little Korn shell syntax here. You'll need to change it a little for another shell.
 
Adding "." to your path works, but is generally considered a bad idea in any production environment.
It leaves the door open to have something run that you do not intend.
Example:
If there was a file called "ls" in your current working directory that was a script that performed an entirely different function (database call, rm or move activity), it could be called in error.
A better practice is to move "approved" executables into an area in the users' path, and only call other files by explicitly stating the directory, literally (/home/myuser/bin/foo.sh) or relatively (./foo.sh)

I admit it is not as convenient, but it could save you a lot of grief.
 
But if you have the . at in the end of the PATH variable then doesn't it search it at the end???
So even if you have the same names then it'll only excute the correct ones ??
 
If you have the "." at the end of the path, it will attempt to execute the first one it finds in your path...but only if you have execute privileges to the file(s) earlier in the path.
If you do not have execute privilege to the file earlier in your path, but can execute the same file name found later in your path, the later file will be run.

It is really a matter of deciding which is more important... taking a shortcut to save a few keystrokes, or staying with established best practices and being certain of what you are running and from where.

Copying/moving commonly used files (once they have been checked out and approved for use) to a directory that is common to everyone's path is safer, and allows the administrator to set privileges to the file to read-execute only (e.g. chmod 755) to avoid it being overwritten or "fixed" by someone who has a great idea but maybe not enough caution.

 
SamBones what is this s..t ??

export PATH=${PATH}:/bin:/usr/bin:/usr/sbin
export PATH=${PATH}:/usr/ucb:/usr/ccs/bin
export PATH=${PATH}:.:

:((((((((((((((((((((((((((((((((((((

you are exporting:
/bin:/usr/bin:/usr/sbin:/bin:/usr/bin:/usr/sbin:usr/ucb:/usr/ccs/bin:/bin:/usr/bin:/usr/sbin:/bin:/usr/bin:/usr/sbin:usr/ucb:/usr/ccs/bin:.:

export PATH
PATH=/bin:/usr/sbin:/usr/ucb:/usr/ccs/bin:.

did you never get the error:
trunking ridiculous long PATH

what's the ~ ?? is this $HOME
did you allready realize /bin is a link to /usr/bin ??
why the ending : ?? -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Thanks guys! Added the path everything works great! I wasn't sure which dot file I needed to change. Thanks again!
 
jamisar,
you've been asked MANY times on this forum and many other forums to keep these forums civilized and proof read your postings both for clearity and to sieve out any personal comments.

I am asking you again - keep these civilized and try to keep your emotions to yourself. This site called "Tek-Tips" and not "Flame-R-us'. If you have problems with any of the posts [personal or otherwise], pls direct your flames to /dev/null and direct your "TIPS" to the forums bearing similar name.

thanks
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
jamisar, take a deep breath, calm down.

In the original post, he said he only had /usr/local/bin defined in his PATH. So, what I gave him results in...
[tt]
PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/ccs/bin:.:~
[/tt]
...not that big long PATH you listed. Each export concatenates to the existing PATH, so it's just adding them to the end.

And the &quot;~&quot; is Korn shell for the user's home directory. If you read my whole post before freaking out, you would have noticed that I mention that this is Korn shell syntax.
 
The tilde (~) represents the home directory in all the shells I've used. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top