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

I know I can execute it with the relative path.

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

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

Or execute it with the absolute path.

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

-bash: command not found

But I can't execute it without any indication.

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

This time, we saw error command not found instead.


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

[scott@test ~]$ vi .bash_profile

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 ~]$
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 *