1

I'm having an issue where I get the error

bash: stp: command not found (stp is the name of the file I am trying to execute)

Even when I have the folder that this program resides inside is in my $PATH variable. A couple of things I've already checked:

-Making sure I am editing the $PATH in the shell that I am operating. I edited the .bashrc file residing in my home directory adding $HOME/bin to the path. I have verified that I am in the bash shell by typing

$ ps $$ which returned bash as the command.

-Making sure that what I added in .bashrc actually affected the path (after restarting the shell, but I have also restarted the computer since then). Typing

$ echo $PATH does indeed return /home/myself/bin as part of the path. I will note that the file of interest lies inside a folder inside of /home/myself/bin, but that shouldn't matter, right?

-Lastly, /pathtofile/stp executes the file as I would expect. Or just making sure I am in the directory and typing ./stp.

So if it's in my $PATH variable, I edited the right configuration file for the bash shell, made sure I am running bash, have restarted the shell since then, I'm sure I'm overlooking something really trivial. I'm still pretty new to Unix/Linux (running Debian), so I don't know all the ins and outs. But from what I understand, I should be able to type $ stp no matter where I am and it should search through the path and find it inside of there.

  • If stp resides in /path/to/tools/; then try adding the following to your script before you attempt to invoke it: PATH="/path/to/tools/:$PATH" – DopeGhoti Dec 5 '16 at 21:28
  • "I will note that the file of interest lies inside a folder inside of /home/myself/bin, but that shouldn't matter, right?" -- makes all the difference. $PATH is not recursive – Jeff Schaller Dec 5 '16 at 21:33
  • I see. Then what is the point of adding /bin to the path if any folders I put in there are not also included? Seems like it would be a mess if you just dumped everything in bin (all the makefiles and other components). I did indeed try adding the directory itself to the path after the fact and it did work. So I guess I learned something today. Thanks! – Aaron A. Dec 5 '16 at 21:43
  • It would be a mess indeed. So you build you code in one corner and then sudo make install to put the executable, libraries, etc in the correct places. (Assuming your makefile has the install target, of course.) – roaima Dec 5 '16 at 22:28
4

I will note that the file of interest lies inside a folder inside of /home/myself/bin, but that shouldn't matter, right?

It does matter, $PATH is not recursive.

You could move the file. Or create a link (hard or symbolic). Probably symbolic will be less confusing:

If the file exists in /home/user/bin/sub-dir/stp, execute:

ln -s sub-dir/stp ~/bin/stp

Or add the new sub-directory to path

PATH=$HOME/bin/sub-dir:$PATH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.