Languages and Scripting
Showing results for 
Search instead for 
Did you mean: 

shell script--Need Help

Occasional Contributor

shell script--Need Help

./ seems do magic in many occasions. What is behind this?


./test.ksh works, but test.ksh give test.ksh not found.



Duncan Edmonstone
Honored Contributor

Re: shell script--Need Help

This is down to the PATH environment variable - i.e. the directories that the shell will look in to execute a command. You can see what it is currently set to using:


echo $PATH


So anything in those directories will be searched to execute the command you type.


I'm assuming you are attempting the command you specify as root? For root it is not a good idea to have the current directory on the PATH as it makes it easy for folks to inject trojans into the system by leaving scripts that attack a system in directories with names similar to standard commands. Of course when you are root you get round this by explicitly referencing the current directory by adding ./ to the start of the command.


If you look at standard .profiles for non-root users you will see that often the current directory is added to the PATH as follows:




But it is NOT a good idea to make this change for root.


Dennis Handly
Acclaimed Contributor

Re: shell script-- $PATH lookup

>./ seems do magic in many occasions. What is behind this?


This is elementary shells 101.

As Duncan said, for all commands that are not relative, absolute or builtin, it looks them up in $PATH.

Adding "./" makes the command have a relative path.