Operating System - HP-UX
1833780 Members
2488 Online
110063 Solutions
New Discussion

Full Path needed to execute a command

 
SOLVED
Go to solution
Jenny C
Advisor

Full Path needed to execute a command

Hi, I couldn't execute a command even I am already inside the path. The error message was:

/sbin/sh: command_name: not found

I had to exit out my path all the way to the top and then type in the full path of the command to be able to execute it.

What's the reason and how do I fix this?

Thanks in advance.
8 REPLIES 8
Eileen Millen
Trusted Contributor
Solution

Re: Full Path needed to execute a command

If you put ./command_name
it should work.
for the .profile file to run you would put
. .profile

Otherwise, you would have to put the path in your .profile file in the PATH statement.

Eileen
S.K. Chan
Honored Contributor

Re: Full Path needed to execute a command

If you're in the directory already type

./

eg:
# cd /dirA/test
# ./runprogram
harry d brown jr
Honored Contributor

Re: Full Path needed to execute a command


Let's say the command was this:

something.sh

Did you type in

something.sh

and it did not execute? or did you enter in this:

./something.sh

The full path

/opt/whatever/something.sh

will always work. Of course you have to have execute permissions set on something.sh.


live free or die

harry


ps: You could add the current working directory to your PATH variable.
Live Free or Die
Christopher McCray_1
Honored Contributor

Re: Full Path needed to execute a command

It is possible that the command that you entered is not in you PATH variable. type in the following:

#which

if the out output returns saying "no in ... (list of paths)", then you have to do one, or all of the following:

1) add the path your command is in:
#export PATH=$PATH:
. also add it to your .profile

2)execute using the absolute path:
#/path/foryour/command

3)from inside the directory
#./command

Also make sre it's executable (just a thought.

Hope this helps.

Chris

It wasn't me!!!!
G. Vrijhoeven
Honored Contributor

Re: Full Path needed to execute a command

Hi.

Like others have mentioned you can use ./command. If that does not work you can also use $PWD/command.

Jenny C
Advisor

Re: Full Path needed to execute a command

Thank you all very much for the quick replies. I really appreciate it. The command worked! I am on my way to learn the simplist things of unix and I might see you again down the road.

Darrell Allen
Honored Contributor

Re: Full Path needed to execute a command

Unlike some OSes, if you don't explicitly tell the shell where to find a command (using absolute or relative pathnames), UNIX will only look in the directories you specify with the PATH environmental variable. So, no matter what directory you are in, the shell will find the command if:
1 - you specify the absolute patch (starting with /) to the command
2 - you specify a relative path (relative from your current directory) such as ./command or ../command or subdir/command
3 - or you specify a simple pathname (just the command name without anything else) and it is found in one of the directories specified in you $PATH variable.

So to fix this, either:
1 - cd to the directory and run the command as ./command
2 - set your PATH manually after you login to include the current (.) directory using export PATH=$PATH:.
3 - set your PATH automatically whenever you login by putting export PATH=$PATH:. in your .profile
4 - you could add . to the PATH variable in /etc/profile but some people consider that a security violation.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Bill Hassell
Honored Contributor

Re: Full Path needed to execute a command

Just a note about security. While being able to cd to a directory and just type a command is convenient, it is a big security risk.

Here's what can happen: Someone places a file in /tmp and calls it su. You cd into /tmp and after a while, you type su. If your $PATH contains :: or :.: then this rogue program or script will be executed--and your password will be stolen.

So your system administrator decided that the current working directory should not be searched unless you take extra steps (the ./) to run the program.


Bill Hassell, sysadmin