Skip to content
Home » Shell Script » How to Resolve Command Not Found in Bash

How to Resolve Command Not Found in Bash

I do have an executable file in the present working directory ($PWD).

[scott@test ~]$ ll
total 4
-rwxr--r-- 1 scott scott 21 Mar 12 12:45 say_hello.sh

I know I can execute it with the relative path.

[scott@test ~]$ ./say_hello.sh
Hello, World!

./ indicates that the execute file is in the present working directory.

Or execute it with the absolute path.

[scott@test ~]$ /home/scott/say_hello.sh
Hello, World!

-bash: command not found

But I can't execute it without any indication.

[scott@test ~]$ say_hello.sh
-bash: say_hello.sh: command not found

This time, we saw error command not found instead.

Solution

To make the shell know what we want to do, we should tell it in advance.

[scott@test ~]$ vi .bash_profile
...
export PATH=$PATH:$HOME

We add our $HOME to be one of discover-able paths of executable files.

Then we take it effect immediately.

[scott@test ~]$ . ~/.bash_profile

We used a dot command to source all environment variables in the profile.

Then we do it again.

[scott@test ~]$ say_hello.sh
Hello, World!

Good, this is what we want. In fact, the customized file can be executed in any directory without modifiers.

Leave a Reply

Your email address will not be published. Required fields are marked *