Operating System - HP-UX
1748128 Members
3676 Online
108758 Solutions
New Discussion

Re: shell script-- $PATH lookup

 
HP-UX-OS
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.

 

Thanks.

2 REPLIES 2

Re: shell script--Need Help

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

 

echo $PATH

 

So anything in those directories will be searched to run 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:

 

PATH=$PATH:.

 

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


I am an HPE Employee
Accept or Kudo
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.