Command not found via shell script but works on terminal

As your script is a shell script (/bin/sh), then your PATH entries in .bashrc will not be read as that is for the bash (/bin/bash) interactive shell.

To make your PATH entries available to /bin/sh scripts run by a specific user, add the PATH entry to the .profile file in that users home directory.


Additionally you could add the full path for each of your commands within the script:

/bin/cp filename.so filename_org.so

Or set the PATH variable including all the required $PATHS at the beginning of your script.

PATH=$PATH:/bin:/usr/bin:xxx
export PATH

Had the same issue while running a binary whose path is set in bashrc.

Solved the issue by doing the following:

Add the binary or add a link to the binary in /usr/bin.

ln -s [path_to_binary] [name_of_executable] 

Then check using

ls -l

You can remove the entry form bashrc.


you can do one simple thing if you have small script and finish your work asap

go on command line use below command

which your_command 

above command will print output including path use that command direct

Tags:

Shell

Bash